Created
August 16, 2012 15:11
-
-
Save racsonp/3370895 to your computer and use it in GitHub Desktop.
ASP.NET Check All CheckBoxes in Grid WebForm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Check All CheckBoxes in Grid WebForm | |
//---------------------------------------------------------------------------------------------- | |
//---------------------------------------------------------------------------------------------- | |
protected void CheckBoxAll_CheckedChanged(object sender, EventArgs e) | |
{ | |
var chkAll = (CheckBox)GridMemberList.HeaderRow.FindControl("CheckBoxAll"); | |
if (chkAll.Checked) | |
{ | |
foreach (var chkSelected in from GridViewRow gvRow in GridMemberList.Rows | |
select (CheckBox)gvRow.FindControl("ChecAttItem")) | |
{ | |
chkSelected.Checked = true; | |
} | |
} | |
else | |
{ | |
foreach ( | |
var chkSel in | |
from GridViewRow gvRow in GridMemberList.Rows | |
select (CheckBox)gvRow.FindControl("ChecAttItem")) | |
{ | |
chkSel.Checked = false; | |
} | |
} | |
} | |
//---------------------------------------------------------------------------------------------- | |
<Columns> | |
<asp:TemplateField HeaderText="Attended" SortExpression="Attended"> | |
<HeaderTemplate> | |
<asp:CheckBox runat="server" ID="CheckBoxAll" ClientIDMode="Static" AutoPostBack="true" | |
OnCheckedChanged="CheckBoxAll_CheckedChanged" Text="Select *" /> | |
<asp:HiddenField runat="server" ID="EmployeeId" Value='<%# Bind("Employee") %>' /> | |
</HeaderTemplate> | |
<ItemTemplate> | |
<asp:CheckBox ID="ChecAttItem" runat="server" Checked='<%# Bind("Attended") %>' /><asp:HiddenField | |
runat="server" ID="EmployeeId" Value='<%# Bind("CommitteeCreationMember1") %>' /> | |
</ItemTemplate> | |
</asp:TemplateField> | |
<asp:TemplateField HeaderText="Committee Member" SortExpression="Employee1"> | |
.......................... | |
</asp:TemplateField> | |
.................. | |
</Columns> | |
</asp:GridView> | |
//---------------------------------------------------------------------------------------------- | |
//---------------------------------------------------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment