0

Double Click event for a Row in a Grid View

1. First while on OnRowDataBound Method of your GridView insert the following:



if (e.Row.RowType == DataControlRowType.DataRow)
{
for (int i = 0; i < (e.Row.Cells.Count); i++)
{
e.Row.Attributes.Add("ondblclick""Javascript:rowDblClick();");
}
}
2. Write a javascript method in your aspx page.

  function rowDblClick(){ 
        alert("done!");
      }
 Thats it you are done !
0

GridView Row Color Change Using CSS

First define the css which you want to use. This you could do by defining a seperate css file or by adding the css in the same file. I have declared the css in the same file. The head section of my .aspx file looks like below.

<head runat="server">
    <title>Untitled Page</title>
    <style>
     .RowCss tr:hover
    {
        background-color:Orange;
    }
    </style>
</head>

Next you have to give this css class to the Grid View where you need to change your row.

 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
 DataSourceID="SqlDataSource1" CssClass="RowCss" >

Expected Output:
0

Check whether a HTML control exists or not


<!DOCTYPE html>
<html> 
<head> 
   <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 
   <title>Check whether a control exists</title> 
</head> 
<body> 
   <script type="text/javascript">
       function check() {
           if (document.getElementById('btn_yasser')) {
               alert('Exists !');
           }
           else {
               alert('Not present');
           }
       }
   </script> 
   <input type="button" id="btn_yasser" value="click me" onClick="check();" /> 
</body> 
</html>
The same could be used for ASP controls.
Hope this helps.
0

Session Management For Grid View Control

I recently came across a situation, where I had to use session management for GRID VIEW CONTROL.


I had a search page where there was a grid displaying some data. Whenever a search was made, the data was fetched from the back end and displayed in the grid view. Now whenever the user navigates to another page and comes back to the search page, my gridview values should be still there. 
Use the code below in the appropriate place. 

// Store GridView in Session
Session["Test"] = GridView1;
GridView1 = null;


// Retrieve GridView from Session
GridView1 = (GridView)Session["Test"];


Hope this helps!
4

Add Row / Columns to GridView (Programmatically)


1) Create a DataTable object to which than we will bind the GridView

DataTable dt = new DataTable();
2) IF you need two columns than create two DataColumn objects

DataColumn dc1 = new DataColumn("first", typeof(string));

DataColumn dc2 = new DataColumn("second", typeof(string));
DataColumn dc3 = new DataColumn("third", typeof(string));

Add it to the table

dt.Columns.Add(dc1);

dt.Columns.Add(dc2);
dt.Columns.Add(dc3);
3)Run the loop for as many rows you want to add. eg: 3 rows to be added.

for(int i=0;i<3;i++)// 3 = number of rows needed.

{
   DataRow row1 = dt.NewRow();
   int c = 0;
   while (c < 3)
   {
       row1[c] = "some_data";
       c++;
   }
   dt.Rows.Add(row1 );
}

Now iterate through each datacolumn and create a BoundField foreach column

foreach (DataColumn col in dt.Columns)

{
BoundField bField = new BoundField();
bField.DataField = col.ColumnName;
bField.HeaderText = col.ColumnName;
GridView1.Columns.Add(bField);
}

GridView1.DataSource = dt;
//Bind the datatable with the GridView.
GridView1.DataBind();
And you have successfully added rows/cols to the grid !
0
Database Basics using C#:


The following demonstrates a Register Page where the user is allowed to register, by entering a username and password. These inputs are saved in a table in database and later verified when user wants to login using the login page.

Section I:
Code for Register Page

    String ConnString = “--Your Connection_String goes here--";
    SqlConnection con = new SqlConnection(ConnString);

    String Command = ”insert into TABLE_NAME values(@username,@password)”;
    SqlCommand cmd = new SqlCommand(command, con);

    con.Open();

    cmd.Parameters.Add(“@username”, SqlDbType.Text).Value = Textusername.Text;
    cmd.Parameters.Add(“@password”, SqlDbType.Text).Value = Textpassword.Text;

    int a = cmd.ExecuteNonQuery();

    if (a > 0)
    {
        Response.Redirect(“~/Login.aspx”);
    }
    else
    {
        lablel.ForeColor = System.Drawing.Color.Red;
        label.Text = “Error Occured!”;
    }

Section II:
Code for Login Page


SqlConnection con = new SqlConnection(connString);
SqlDataAdapter da = new SqlDataAdapter(“select * from userinfo”, con);
DataSet ds = new DataSet();
da.Fill(ds, “info”);

string username = Textusername.Text;
string password = Textpassword.Text;

int find = 0;
foreach (DataRow dr in ds.Tables["info"].Rows)
{
    if (username == dr["username"].ToString())
    {
        if (password == dr["password"].ToString())
        {
        find = 1;
        break;
        } // end of 1st if
    }// end of 2nd if
} // end of for each

if (find == 1)
{
    Response.Redirect(“~/Home.aspx”);
}
else
{
    Labelerror.ForeColor = System.Drawing.Color.Red;
    Labelerror.Text = “Username Password Mismatch”;
}



0

SET PATH IN WINDOWS 7


Setting Path on Windows 7
  1. Start -> Control Panel -> System -> Advanced
  2. Click on Environment Variables, under System Variables, find PATH, and click on it.
  3. In the Edit windows, modify PATH by adding the location of the class to the value for PATH. If you do not have the item PATH, you may select to add a new variable and add PATH as the name and the location of the class as the value.
  4. Close the window.
 Hope this helps! :)
0

Best place to learn Jquery

0

Simple AJAX Tutorial



As usual, we will use the good old "Hello, world!" as our very first example. We will begin with the code, and then we'll do a bit of explanation afterwards. If you haven't already done so, you should create a new ASP.NET website project in Visual Web Developer. The IDE will create a Default.aspx and Default.aspx.cs file for you, which will look just like any other ASP.NET enabled page. Let's add some AJAX to it:
<%@ 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>Hello, world!</title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="MainScriptManager" runat="server" />
        <asp:UpdatePanel ID="pnlHelloWorld" runat="server">
            <ContentTemplate>
                <asp:Label runat="server" ID="lblHelloWorld" Text="Click the button!" />
                <br /><br />
                <asp:Button runat="server" ID="btnHelloWorld" OnClick="btnHelloWorld_Click" Text="Update label!" />
            </ContentTemplate>
        </asp:UpdatePanel>
    </form>
</body>
</html>
In the CodeBehind, there's nothing new except for this event which you should add:
protected void btnHelloWorld_Click(object sender, EventArgs e)
{
    lblHelloWorld.Text = "Hello, world - this is a fresh message from ASP.NET AJAX! The time right now is: " + DateTime.Now.ToLongTimeString();
}
In the markup part, we use two new things, when compared to regular ASP.NET: The ScriptManager control and the UpdatePanel control. The ScriptManager makes sure that the required ASP.NET AJAX files are included and that AJAX support is added, and has to be included on every page where you wish to use AJAX functionality. After the manager, we have one of the most used controls when working with AJAX, the UpdatePanel. This control allows you to wrap markup which you would like to allow to be partially updated, that is, updated without causing a real postback to the server. More about the UpdatePanel in a coming chapter. Besides those two controls, everything else is standard controls, with no modifications that would indicate alternate behavior.

Try running the example site, and click the button. The label will be updated with our usual Hello world text, and the current time. Try repeatedly clicking the button, and you will see the label get the current timestamp each time. Notice the wonderful absence of a blinking window and a running status bar - everything is done without updating anything but the label! We've just created our first AJAX enabled page
1

AJAX TabContainer Tutorial

An ASP.NET AJAX TabContainer creates a set of Tabs that can be used to save screen space and organize content. The TabContainer contains a number of TabPanel controls. You can place your controls inside each TabPanel. In this article, we will explore some common tips and tricks with the ASP.NET AJAX TabContainer control.
1. How to Create a ASP.NET AJAX TabContainer with Tab Panels

Assuming you have AJAX Control Toolkit for 3.5 installed, Open Visual Studio 2008 > File > New Website > ‘ASP.NET WebSite’ > Enter a name and location for the project > Click Ok.
Drag and drop a <ScriptManager> from the Toolbox to the page. Now drag and drop a TabContainer to the page and using the smart tag, add a few tabpanels. Switch to the source view and add <ContentTemplates> inside each TabPanel. You can now place controls inside the <ContentTemplates>. The code will look similar to the following:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>

<!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>Tab Container Tips & Tricks By Yasser</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>   
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
   
        <cc1:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="0">
       
            <cc1:TabPanel ID="TabPanel1" runat="server" HeaderText="TabPanel1">
                <ContentTemplate>
                    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
                    <asp:Button ID="Button1" runat="server" Text="Button" />
                </ContentTemplate>
            </cc1:TabPanel>
           
            <cc1:TabPanel ID="TabPanel2" runat="server" HeaderText="TabPanel2">
                <ContentTemplate>
                    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />
                    <asp:Button ID="Button2" runat="server" Text="Button" />
                </ContentTemplate>
            </cc1:TabPanel>
                      
            <cc1:TabPanel ID="TabPanel3" runat="server" HeaderText="TabPanel3">
                <ContentTemplate>
                    <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox><br />
                    <asp:Button ID="Button3" runat="server" Text="Button" />
                </ContentTemplate>
            </cc1:TabPanel>
           
        </cc1:TabContainer>
        <br />
   
    </div>
    </form>
</body>
</html>


2. How to add an image in the Header of each TabPanel in an ASP.NET AJAX TabContainer

Use <HeaderTemplate>.
You can then add an image as shown below:
   <cc1:TabPanel ID="TabPanel1" runat="server">
       <HeaderTemplate>
           <img src="search.jpg" alt="Tab1"/>
       </HeaderTemplate>
       <ContentTemplate>
           <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
       </ContentTemplate>
   </cc1:TabPanel>

 

2011 ·Code-Studio by yrus.