Hi frnz
how can i select all the checkboxes in agridview
<asp:GridView ID="gvApplicable" runat="server" AutoGenerateColumns="False"
AllowSorting="True" AllowPaging="True" PageSize="15" onrowediting="gvApplicable_RowEditing"
onpageindexchanging="gvApplicable_PageIndexChanging" Height="127px"
onselectedindexchanged="gvApplicable_SelectedIndexChanged" Width="213px" >
<Columns>
<asp:TemplateField >
HeaderTemplate>
<asp:CheckBox ID="chkSelectAll" runat="server"
AutoPostBack="true"
OnCheckedChanged="chkSelectAll_CheckedChanged"/>
HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="Chk1" runat="server" />
ItemTemplate>
asp:TemplateField>
<asp:BoundField ReadOnly="true" DataField="DeptCode" HeaderText="Code" InsertVisible="false" SortExpression="Code">asp:BoundField>
<asp:BoundField ReadOnly="true" DataField="DeptName" HeaderText="DeparmentName" InsertVisible="false" SortExpression="Name">asp:BoundField>
Columns>
asp:GridView>
Loading
Soft CornerPosted Dec 23, 2010, 5:46 AM
Solution for your code :-
protected void chkSelectAll_CheckedChanged(object sender, EventArgs e)
{
CheckBox chkbox = new CheckBox();
CheckBox chkbox1 = new CheckBox();
chkbox = (CheckBox)gvApplicable.HeaderRow.FindControl("chkSelectAll");
foreach (GridViewRow row in gvApplicable.Rows)
{
chkbox1 = (CheckBox)row.FindControl("Chk1");
if (chkbox.Checked == true)
{
chkbox1.Checked = true;
}
else
{
chkbox1.Checked = false;
}
}
}
Krishna GaradPosted Dec 24, 2010, 1:18 AM
;ike this
sandeep kodepakaPosted Dec 24, 2010, 12:55 AM
thanx for the solution, but i have one more problem i will expalin the scenario
i have 3 radiobuttons and 3 griviews and one button to select all the checkboxes in the gridview.k
if i select 1st radiobutton then iam able to select all the checkboxes in the gridview,
but if i iam selecting the second radiobutton then how to select all the checkboxes
and if i select 3rd radiobutton then how to select the checkbox in the grid view
can u please help me
Krishna GaradPosted Dec 23, 2010, 5:19 AM