GridView (Multiple check Boxes Selection / Get Checked Check Boxes)
Grid View
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"> <Columns> <asp:BoundField DataField="Column1" HeaderText="Column" /> <asp:TemplateField HeaderText="TextBox"> <ItemTemplate> <asp:TextBox ID="txt_TextBox" runat="server"></asp:TextBox> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Select"> <HeaderTemplate>
Select All
<input id="chkAll" onclick="javascript:SelectAllCheckboxes(this);" runat="server" type="checkbox" /> </HeaderTemplate> <ItemTemplate> <asp:CheckBox ID="chk_Selected" runat="server" /> </ItemTemplate> </asp:TemplateField></Columns> </asp:GridView>
JavaScript
<
script language="javascript"> function SelectAllCheckboxes(spanChk){ var oItem = spanChk.children; var theBox= (spanChk.type=="checkbox") ?spanChk : spanChk.children.item[0];
xState=theBox.checked;
elm=theBox.form.elements;
for(i=0;i<elm.length;i++) if(elm[i].type=="checkbox" &&elm[i].id!=theBox.id)
{
if(elm[i].checked!=xState)elm[i].click();
}
}
</
script>Code Behind
string str_Result = ""; for (int i = 0; i < gv_SearchedDocuments.Rows.Count; i++){
GridViewRow gv_row = GridView1.Rows[i]; bool isChecked = ((CheckBox)gv_row.FindControl("chk_Selected")).Checked; if (isChecked){
str_Result += GridView1.Rows[i].Cells[0].Text;
TextBox txt_Temp = ((TextBox)gv_row.FindControl("txt_ViewOrder"));str_Result +=
txt_Temp.Text+"<,br/>";}
}
lbl_Message.Text = str_Result ;
Comments