Hi,
i have gridview with checkbox column , in it when i clik on Header checkbox , its event fires Multiple Times.
can anyone has solution for this
thanks in advance
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Gridview_Checkbox_Example1.aspx.cs"
Inherits="Gridview_Checkbox_Example1" EnableEventValidation="false" %>
<!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 id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdateProgress ID="UpdateProgress2" runat="server" DisplayAfter="10" Visible="true">
<ProgressTemplate>
<div class="progressn">
<span>Loading Please Wait...</span>
</div>
</ProgressTemplate>
</asp:UpdateProgress>
<asp:UpdatePanel ID="UP2" runat="server">
<ContentTemplate>
<div>
<table cellpadding="4" cellspacing="0">
<tr>
<td align="left" valign="top">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" CssClass="Gridview"
ShowFooter="true" OnRowDataBound="GridView1_RowDataBound" CellPadding="4" AllowPaging="false"
AllowSorting="false" DataKeyNames="ID,NAME">
<HeaderStyle BackColor="#9CAAC1" Font-Bold="True" ForeColor="White" HorizontalAlign="Center" />
<PagerStyle BackColor="#9CAAC1" Font-Bold="True" ForeColor="Black" HorizontalAlign="Center" />
<FooterStyle BackColor="#9CAAC1" Font-Bold="True" ForeColor="Black" HorizontalAlign="Center" />
<RowStyle BackColor="White" ForeColor="Black" Font-Names="Verdana" Font-Size="12px" />
<SelectedRowStyle BackColor="lightGray" Font-Bold="false" ForeColor="Black" Font-Names="Verdana"
Font-Size="12px" />
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" HeaderStyle-HorizontalAlign="Center"
ItemStyle-HorizontalAlign="Right" />
<asp:BoundField DataField="NAME" HeaderText="NAME" HeaderStyle-HorizontalAlign="Center"
ItemStyle-HorizontalAlign="Left" />
<asp:BoundField DataField="Country" HeaderText="Country" HeaderStyle-HorizontalAlign="Center"
ItemStyle-HorizontalAlign="Left" />
<asp:TemplateField HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center"
HeaderStyle-Wrap="true" ItemStyle-Wrap="true" ItemStyle-VerticalAlign="Middle"
HeaderStyle-Width="35px" ItemStyle-Width="35px">
<HeaderTemplate>
<asp:CheckBox ID="chkAll2" runat="server" onclick="checkAll(this);" AutoPostBack="true"
OnCheckedChanged="cbSingle2_CheckedChanged"/>
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="cbSingle2" runat="server" onclick="Check_Click(this)" AutoPostBack="true"
OnCheckedChanged="cbSingle2_CheckedChanged" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
public partial class Gridview_Checkbox_Example1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Fill_GV();
}
}
public void Fill_GV()
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[4] { new DataColumn("Id"), new DataColumn("Gender"), new DataColumn("Name"), new DataColumn("Country") });
dt.Rows.Add(1, "M", "AAAAAA", "AAAAAA");
dt.Rows.Add(2, "M", "BBBBBB", "BBBBBB");
dt.Rows.Add(3, "F", "CCCCCC", "CCCCCC");
dt.Rows.Add(4, "M", "DDDDDD", "DDDDDD");
GridView1.DataSource = dt;
GridView1.DataBind();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
foreach (TableCell tc in e.Row.Cells)
{
tc.Attributes["style"] = "border:1px solid black;";
}
if (e.Row.RowType == System.Web.UI.WebControls.DataControlRowType.DataRow)
{
}
}
protected void cbSingle2_CheckedChanged(object sender, EventArgs e)
{
CheckBox chk = (CheckBox)sender;
string ID1 = chk.ID;
string ID2 = chk.ClientID.ToString();
string ID3 = chk.UniqueID.ToString();
}
public override void VerifyRenderingInServerForm(Control control)
{
/* Verifies that the control is rendered */
}
}