my .cs file is
using System;
using System.Data;
using System.Configuration;
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;
public partial class _Default : System.Web.UI.Page
{
DataTable dt;
DataTable DBView = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack == false )
{
dt = new DataTable("tblTest");
DataColumn dc1 = new DataColumn();
dc1.DataType = typeof(String);
dc1.ColumnName = "Name";
DataColumn dc2 = new DataColumn();
dc2.DataType = typeof(String);
dc2.ColumnName = "Add1";
DataColumn dc3 = new DataColumn();
dc3.DataType = typeof(String);
dc3.ColumnName = "Add2";
dt.Columns.Add(dc1);
dt.Columns.Add(dc2);
dt.Columns.Add(dc3);
Session["Name"] = "Rupa" + "|";
Session["Add1"] = "3" + "|";
Session["Add2"] = "ffdfd" + "|";
CreateTable();
Session["Name"] = "Rupa2" + "|";
Session["Add1"] = "1" + "|";
Session["Add2"] = "ffdfd" + "|";
CreateTable();
Session["Name"] = "Rupa3" + "|";
Session["Add1"] = "4" + "|";
Session["Add2"] = "ffdfd" + "|";
CreateTable();
Session["Name"] = "Rupa4" + "|";
Session["Add1"] = "5" + "|";
Session["Add2"] = "ffdfd" + "|";
CreateTable();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
int cnt = GridView1.Rows.Count;
for (int i = 0; i < cnt; i++)
if (((CheckBox)(GridView1.Rows[i].Cells[0].FindControl("CheckBox1"))).Checked == true)
GridView1.Rows[i].BackColor = System.Drawing.Color.AliceBlue;
}
public void CreateTable()
{
string[] sa = Session["Name"].ToString().Split('|');
string[] sb = Session["Add1"].ToString().Split('|');
string[] sc = Session["Add2"].ToString().Split('|');
int recordnum = sa.Length;
for (int j = 0; j < recordnum - 1; j++)
{
DataRow dr = dt.NewRow();
dr["Name"] = sa[j].ToString();
dr["Add1"] = sb[j].ToString();
dr["Add2"] = sc[j].ToString();
dt.Rows.Add(dr);
}
GridView1.DataSource = dt.DefaultView;
GridView1.DataBind();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
}
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
DataView DBView;
DataTable Dbdatatable;
DBView = dt.DefaultView;
string sDirection;
if (ViewState["sortDirection"] == null)
{
ViewState["sortDirection"] = SortDirection.Ascending;
sDirection = " ASC";
}
else
{
ViewState["sortDirection"] = SortDirection.Descending;
sDirection = " DESC";
}
DBView.Sort = e.SortExpression;// +SortDirection.Ascending;
this.GridView1.DataSource = dt;
this.GridView1.DataBind();
}
protected void Button1_Click1(object sender, EventArgs e)
{
int rowCount = GridView1.Rows.Count;
for (int i=0;i<rowCount;i++)
{
if (((CheckBox)(GridView1.Rows[i].Cells[0].FindControl("CheckBox1"))).Checked == true)
GridView1.Rows[i].BackColor = System.Drawing.Color.PaleGreen;
}
}
}
my aspx file is
<%@ 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>Untitled Page</title>
</head>
<body>
<script type="text/javascript" src="wz_tooltip.js">
//function Button1_onclick()
//{
//document[0].write("HAi");
//}
</script>
<form id="form1" runat="server">
<a href="Default.aspx" onmouseover="Tip('Some text')">Homepage </a>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" OnPageIndexChanging="GridView1_PageIndexChanging" PageSize="2" OnSorting="GridView1_Sorting">
<Columns>
<asp:CheckBoxField />
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="SE Name">
<ItemTemplate>
<a href="<%# String.Format("~/Default2.aspx?Name={0}", Eval("Name")) %>" onmouseover="Tip('<%# Eval("Name")%>')" onmouseout="hide('<%# Eval("Name") %>')"><%# Eval("Add1")%>'</a>
<%--<div style="display:none;" id='<%# Eval("Name") %>'><%# Eval("Name")%></div>--%>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<div>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click1" Text="Button" /></div>
</form>
</body>
</html>