Thursday, 13 February 2014

JQuery - Formatting GridView Using JQuery

Step 1
Download JQuery jquery-1.6.1.min.js

Step 2
Create a Web Application and give the Solution name as SolFormattingGridView_Jquery

Step 3
Add a grid view control on page it is look like this
<div>
         
        <asp:GridView ID="GvDeveloper" runat="server" >
        </asp:GridView>
         
    </div>  

Step 4
Add jQuery file Reference inside the head tag of the page

<head runat="server">
    <title>Formatting GridView using Jquery</title>
 
     
    <script src="Scripts/jquery-1.6.1.min.js" type="text/javascript"></script>
 
</head>  

Step 5
Create a CSS for formatting GridView.
<style type="text/css">
         
        .HeaderColor
        {
            background-color:#292421;
            color:#FFFAFA;
            }
         
        .AlterNativeRowColor
       {
           background-color:#EEC591;
           }
           
           .DefaultRowColor
           {
               background-color:#9C661F;
               }    
     
</style>  

Step 6
Write a JQuery script for formatting a gridview.

<script language="javascript" type="text/javascript">
        $(document).ready(function () {
 
            // Header Color
            $("#GvDeveloper th").addClass("HeaderColor");
 
            // Alternative Row Color
            $("#GvDeveloper tr").filter(":odd").addClass("AlterNativeRowColor");
 
            // Default Row Color  
            $("#GvDeveloper tr").filter(":even").addClass("DefaultRowColor");
 
           
 
        });
     
</script>  

jQuery provides  ":odd" and ":even" selector. ":odd" selector which selects only odd elements. ":even" selector which selects even elements.
in short  Rows which are having odd numbers like Row1, Row3, Row5 etc. and even number like   Row2,Row4,Row6 etc.
So we need to filter out all the odd rows and even rows for assign the color.To filter the rows, we will use filter() method of jQuery, which takes selector as argument and returns the elements which matches the selector.
then Adds the specified css classes to each of the set of matched elements.



Full Code
          .aspx Code
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Formatting GridView using Jquery</title>
 
    <style type="text/css">
         
        .HeaderColor
        {
            background-color:#292421;
            color:#FFFAFA;
            }
         
        .AlterNativeRowColor
       {
           background-color:#EEC591;
           }
           
           .DefaultRowColor
           {
               background-color:#9C661F;
               }    
    </style>
 
    <script src="Scripts/jquery-1.6.1.min.js" type="text/javascript"></script>
 
    <script language="javascript" type="text/javascript">
 
        $(document).ready(function () {
 
            // Header Color
            $("#GvDeveloper th").addClass("HeaderColor");
 
            // Alternative Row Color
            $("#GvDeveloper tr").filter(":odd").addClass("AlterNativeRowColor");
 
            // Default Row Color  
            $("#GvDeveloper tr").filter(":even").addClass("DefaultRowColor");
 
           
 
        });
    </script>
 
</head>
<body>
    <form id="form1" runat="server">
    <div>
         
        <asp:GridView ID="GvDeveloper" runat="server" >
        </asp:GridView>
         
    </div>
    </form>
</body>
</html

ASP.net - Access master page control,property,method from content page

At times, it is required to put some of the control,methods, properties in master page and access it from the content pages.

Let see how to access master page control,property,method from content page

Step 1
Create a web application and add the master page inside the web application.if you don't know how to create a master page then you have to see this Master Page article.

Step 2
After creating a master page add the label control in the master page it is look like this


<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
 
</head>
<body>
    <form id="form1" runat="server">
    <div>
 
        <asp:Label ID="lblUserName" runat="server"></asp:Label><br />
     
        <asp:Label ID="lblFirstName" runat="server"></asp:Label><br />
        <asp:Label ID="lblLastName" runat="server"></asp:Label><br />
         
        <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
        </asp:ContentPlaceHolder>
     
    </div>
    </form>
 
</body>
</html>

Step 3
Write a method and property in a master page for accessing method and property from the content page.The members of MasterPage that should be accessed in content pages should be public,it is look like this

Master Page Code behind
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

public partial class MasterPage : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            lblFirstName.Text = FirstName;
           
        }
        catch (Exception)
        { }
    }

    #region Property

    /// <summary>
    /// Get and Set the first Name
    /// </summary>
    public String FirstName
    {
        get;
        set;
    }

    #endregion

    #region Method

    /// <summary>
    /// Set the last Name
    /// </summary>
    /// <param name="LastName"></param>
    public void LastName(String LastName)
    {
        try
        {
            lblLastName.Text = LastName.Trim();  
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message);
        }
    }

    #endregion
}

Step 4
Add a content page it is look like this

Default.aspx
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Title="Untitled Page" %>


<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
</asp:Content>
Step 5
Use @ MasterType directive in content page,it is look like this

<%@ MasterType VirtualPath="~/MasterPage.master"%>

@ MasterType
Include a MasterType directive in every content page where we need to access MasterPage members.

VirtualPath
Specifies the path to the file that generates the strong type.

finally the content page whould look like this


<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Title="Untitled Page" %>
<%@ MasterType VirtualPath="~/MasterPage.master"%>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
</asp:Content>

Step 6
Access control,property and method from content page,it is look like this

Content Page Code behind [Default.aspx.cs]

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            /// Access Master Page control
            Label lblUserName = (Label)this.Master.FindControl("lblUserName");
            lblUserName.Text = "KishorNaik";

            //// Access Master Page Property
            this.Master.FirstName = "Kishor";

            //// Access Master Page Method
            this.Master.LastName("Naik");

        }
        catch (Exception)
        { }
    }
}

Windows Keyboard Shortcuts

Keyboard Shortcuts (Microsoft Windows)
1. CTRL+C (Copy)
2. CTRL+X (Cut)
3. CTRL+V (Paste)
4. CTRL+Z (Undo)
5. DELETE (Delete)
6. SHIFT+DELETE (Delete the selected item permanently without placing the item in the Recycle Bin)
7. CTRL while dragging an item (Copy the selected item)
8. CTRL+SHIFT while dragging an item (Create a shortcut to the selected item)
9. F2 key (Rename the selected item)
10. CTRL+RIGHT ARROW (Move the insertion point to the beginning of the next word)
11. CTRL+LEFT ARROW (Move the insertion point to the beginning of the previous word)
12. CTRL+DOWN ARROW (Move the insertion point to the beginning of the next paragraph)
13. CTRL+UP ARROW (Move the insertion point to the beginning of the previous paragraph)
14. CTRL+SHIFT with any of the arrow keys (Highlight a block of text)

SHIFT with any of the arrow keys (Select more than one item in a window or on the desktop, or select text in a document)
15. CTRL+A (Select all)
16. F3 key (Search for a file or a folder)
17. ALT+ENTER (View the properties for the selected item)
18. ALT+F4 (Close the active item, or quit the active program)
19. ALT+ENTER (Display the properties of the selected object)
20. ALT+SPACEBAR (Open the shortcut menu for the active window)
21. CTRL+F4 (Close the active document in programs that enable you to have multiple documents open simultaneously)
22. ALT+TAB (Switch between the open items)
23. ALT+ESC (Cycle through items in the order that they had been opened)
24. F6 key (Cycle through the screen elements in a window or on the desktop)
25. F4 key (Display the Address bar list in MyComputer or Windows Explorer)
26. SHIFT+F10 (Display the shortcut menu for the selected item)
27. ALT+SPACEBAR (Display the System menu for the active window)
28. CTRL+ESC (Display the Start menu)
29. ALT+Underlined letter in a menu name (Display the corresponding menu) Underlined letter in a command name on an open menu (Perform the corresponding command)
30. F10 key (Activate the menu bar in the active program)
31. RIGHT ARROW (Open the next menu to the right, or open a sub menu)
32. LEFT ARROW (Open the next menu to the left, or close a sub menu)
33. F5 key (Update the active window)
34. BACKSPACE (View the folder one level up in My Computer or Windows Explorer)
35. ESC (Cancel the current task)
36. SHIFT when you insert a CD-ROM into the CD-ROM drive (Prevent the CD-ROM from automatically playing)

Dialog Box - Keyboard Shortcuts
1. CTRL+TAB (Move forward through the tabs)
2. CTRL+SHIFT+TAB (Move backward through the tabs)
3. TAB (Move forward through the options)
4. SHIFT+TAB (Move backward through the options)
5. ALT+Underlined letter (Perform the corresponding command or select the corresponding option)
6. ENTER (Perform the command for the active option or button)
7. SPACEBAR (Select or clear the check box if the active option is a check box)
8. Arrow keys (Select a button if the active option is a group of option buttons)
9. F1 key (Display Help)
10. F4 key (Display the items in the active list)
11. BACKSPACE (Open a folder one level up if a folder is selected in the Save As or Open dialog box)

Microsoft Natural Keyboard Shortcuts
1. Windows Logo (Display or hide the Start menu)
2. Windows Logo+BREAK (Display the System Properties dialog box)
3. Windows Logo+D (Display the desktop)
4. Windows Logo+M (Minimize all of the windows)
5. Windows Logo+SHIFT+M (Restore the minimized windows)
6. Windows Logo+E (Open My Computer)
7. Windows Logo+F (Search for a file or a folder)
8. CTRL+Windows Logo+F (Search for computers)
9. Windows Logo+F1 (Display Windows Help)
10. Windows Logo+ L (Lock the keyboard)
11. Windows Logo+R (Open the Run dialog box)
12. Windows Logo+U (Open Utility Manager)
13. Accessibility Keyboard Shortcuts
14. Right SHIFT for eight seconds (Switch Filter Keys either on or off)
15. Left ALT+left SHIFT+PRINT SCREEN (Switch High Contrast either on or off)
16. Left ALT+left SHIFT+NUM LOCK (Switch the Mouse Keys either on or off)
17. SHIFT five times (Switch the Sticky Keys either on or off)
18. NUM LOCK for five seconds (Switch the Toggle Keys either on or off)
19. Windows Logo +U (Open Utility Manager)
20. Windows Explorer Keyboard Shortcuts
21. END (Display the bottom of the active window)
22. HOME (Display the top of the active window)
23. NUM LOCK+Asterisk sign (*) (Display all of the sub folders that are under the selected folder)
24. NUM LOCK+Plus sign (+) (Display the contents of the selected folder)
25. NUM LOCK+Minus sign (-) (Collapse the selected folder)
26. LEFT ARROW (Collapse the current selection if it is expanded, or select the parent folder)
27. RIGHT ARROW (Display the current selection if it is collapsed, or select the first sub folder)

Shortcut Keys for Character Map
After you double-click a character on the grid of characters, you can move through the grid by using the keyboard shortcuts:
1. RIGHT ARROW (Move to the right or to the beginning of the next line)
2. LEFT ARROW (Move to the left or to the end of the previous line)
3. UP ARROW (Move up one row)
4. DOWN ARROW (Move down one row)
5. PAGE UP (Move up one screen at a time)
6. PAGE DOWN (Move down one screen at a time)
7. HOME (Move to the beginning of the line)
8. END (Move to the end of the line)
9. CTRL+HOME (Move to the first character)
10. CTRL+END (Move to the last character)
11. SPACEBAR (Switch between Enlarged and Normal mode when a character is selected)

Microsoft Management Console (MMC)
Main Window Keyboard Shortcuts
1. CTRL+O (Open a saved console)
2. CTRL+N (Open a new console)
3. CTRL+S (Save the open console)
4. CTRL+M (Add or remove a console item)
5. CTRL+W (Open a new window)
6. F5 key (Update the content of all console windows)
7. ALT+SPACEBAR (Display the MMC window menu)
8. ALT+F4 (Close the console)
9. ALT+A (Display the Action menu)
10. ALT+V (Display the View menu)
11. ALT+F (Display the File menu)
12. ALT+O (Display the Favorites menu)

MMC Console Window Keyboard Shortcuts
1. CTRL+P (Print the current page or active pane)
2. ALT+Minus sign (-) (Display the window menu for the active console window)
3. SHIFT+F10 (Display the Action shortcut menu for the selected item)
4. F1 key (Open the Help topic, if any, for the selected item)
5. F5 key (Update the content of all console windows)
6. CTRL+F10 (Maximize the active console window)
7. CTRL+F5 (Restore the active console window)
8. ALT+ENTER (Display the Properties dialog box, if any, for the selected item)
9. F2 key (Rename the selected item)
10. CTRL+F4 (Close the active console window. When a console has only one console window, this shortcut closes the console)

Remote Desktop Connection Navigation
1. CTRL+ALT+END (Open the Microsoft Windows NT Security dialog box)
2. ALT+PAGE UP (Switch between programs from left to right)
3. ALT+PAGE DOWN (Switch between programs from right to left)
4. ALT+INSERT (Cycle through the programs in most recently used order)
5. ALT+HOME (Display the Start menu)
6. CTRL+ALT+BREAK (Switch the client computer between a window and a full screen)
7. ALT+DELETE (Display the Windows menu)
8. CTRL+ALT+Minus sign (-) (Place a snapshot of the active window in the client on the Terminal server clipboard and provide the same functionality as pressing PRINT SCREEN on a local computer.)
9. CTRL+ALT+Plus sign (+) (Place a snapshot of the entire client window area on the Terminal server clipboard and provide the same functionality as pressing ALT+PRINT SCREEN on a local computer.)

Microsoft Internet Explorer Keyboard Shortcuts
1. CTRL+B (Open the Organize Favorites dialog box)
2. CTRL+E (Open the Search bar)
3. CTRL+F (Start the Find utility)
4. CTRL+H (Open the History bar)
5. CTRL+I (Open the Favorites bar)
6. CTRL+L (Open the Open dialog box)
7. CTRL+N (Start another instance of the browser with the same Web address)
8. CTRL+O (Open the Open dialog box,the same as CTRL+L)
9. CTRL+P (Open the Print dialog ox)
10. CTRL+R (Update the current Web )

Wednesday, 12 February 2014

How To Create Undeletable And Unrenamable Folders ?

Go to Start and then Click on Run
Type cmd & hit enter (To open Command Prompt ).

Remember you cannot create Undeletable & unrenamable folder in your root directory (i.e. where the windows is installed) That means you can't make this kind of folder in C: drive if you installed windows on C:

Type D: or E: and hit enter
Type md con\ and hit enter (md - make directory)
You may use other words such as aux, lpt1, lpt2, lpt3 up to lpt9 instead of con in above step.
Open that directory, you will see the folder created of name con.

Try to delete that folder or rename that folder windows will show the error message.
How to delete that folder ?

It is not possible to delete that folder manually but you can delete this folder by another way mentioned below.

Open Command Prompt
Type D: ( if u created this type of folder in D: drive) & hit enter
Type rd con\ (rd - remove directory)

Open that directory and the folder will not appear because it is removed.

Excel to Sql in C#

Using System.Data.OLEDB;
Using System.Data.SqlClient;

public void ExcelToSQL(string excelpath)
{
   
    string ssqltable = "tableName";
   
    string myexceldataquery = "select student,rollno,course from [sheet1$]";
    try
    {
   
        string sexcelconnectionstring = @"provider=microsoft.jet.oledb.4.0;data source=" + excelfilepath +
        ";extended properties=" + "\"excel 8.0;hdr=yes;\"";
        string ssqlconnectionstring = "server=mydatabaseservername;user
        id=dbuserid;password=dbuserpassword;database=databasename;connection reset=false";
     
        string sclearsql = "delete from " + ssqltable;
        sqlconnection sqlconn = new sqlconnection(ssqlconnectionstring);
        sqlcommand sqlcmd = new sqlcommand(sclearsql, sqlconn);
        sqlconn.open();
        sqlcmd.executenonquery();
        sqlconn.close();
     
        oledbconnection oledbconn = new oledbconnection(sexcelconnectionstring);
        oledbcommand oledbcmd = new oledbcommand(myexceldataquery, oledbconn);
        oledbconn.open();
        oledbdatareader dr = oledbcmd.executereader();
        sqlbulkcopy bulkcopy = new sqlbulkcopy(ssqlconnectionstring);
        bulkcopy.destinationtablename = ssqltable;
        while (dr.read())
        {
            bulkcopy.writetoserver(dr);
        }
   
        oledbconn.close();
    }
    catch (exception ex)
    {
       
    }
}