Checking All CheckBoxes in a GridView
In the code you can checking All CheckBoxes in a GridView follwing is the image of interface .
Copy the following javascript code and put it inside the head tag .
Javascript Code for ASP.Net GridView Check All Checkbox
Using the Client Side Javascript checking the header checkbox would check all checkboxes in the GridView and after unchecking the
header checkbox would uncheck all checkboxes in the GridView .
Copy the following javascript code and put it inside the head tag .
Javascript Code for ASP.Net GridView Check All Checkbox
<script type="text/javascript">
function chkAllCheckbox(obj) {
var gv = document.getElementById('<%=GVMain.ClientID %>');
for (var i = 0; i < gv.all.length; i++) {
var node = gv.all[i];
node.checked = obj.checked;
}
}
</script>
HTML Code for ASP.Net GridView Check All Checkbox
<asp:GridView ID="GVMain" runat="server" AutoGenerateColumns="False" BackColor="White"
BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3">
<RowStyle ForeColor="#000066" />
<Columns>
<asp:TemplateField HeaderText="Select All">
<HeaderTemplate>
<asp:CheckBox ID="chkSelectAll" onClick="javascript:chkAllCheckbox(this);" Text="Select All" runat="server" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ID">
<ItemTemplate>
<asp:Label ID="lblID" Text='<%# Eval("ID") %>' runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:Label ID="lblName" Text='<%# Eval("Name") %>' runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="White" ForeColor="#000066" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
</asp:GridView>

it is very helpful.Thank you
ReplyDeleteits working. thanks =D
ReplyDeleteNice post...But how will i bind the data from database to my grid???Post the corresponding code..
ReplyDeletefor gridview bind code is please visit http://hamidseta.blogspot.com/2011/05/nested-gridview-in-aspnet.html
ReplyDeleteNice post ..it is useful .
ReplyDelete