In this article we will see how to check and un-check checkboxes items in ASP.NET DataGrid using JavaScript. We will also see how to delete all checked items and to change Datagrid row background color on mouse over.

Code:
<asp:DataGrid ID="MyDataGrid" AutoGenerateColumns="false" runat="server"
AllowPaging="true" PagerStyle-Mode="NextPrev"
onitemdatabound="MyDataGrid_ItemDataBound" ShowFooter="true"
onpageindexchanged="MyDataGrid_PageIndexChanged" PageSize="4"
onitemcommand="MyDataGrid_ItemCommand" Width="100%">
<Columns>
<asp:BoundColumn HeaderText="CustomerId" DataField="CustomerId"></asp:BoundColumn>
<asp:BoundColumn HeaderText="Name" DataField="Name"></asp:BoundColumn>
<asp:BoundColumn HeaderText="City" DataField="City"></asp:BoundColumn>
<asp:BoundColumn HeaderText="Mobile" DataField="Mobile"></asp:BoundColumn>
<asp:BoundColumn HeaderText="Address" DataField="Address"></asp:BoundColumn>
<asp:BoundColumn HeaderText="Date Of
Birth" DataFormatString="{0:MM/dd/yyyy}" DataField="DOB"></asp:BoundColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:CheckBox ID="cbRows" runat="server"/>
</ItemTemplate>
<HeaderTemplate>
<input
type="checkbox"
id="mainCB"
onclick="javascript:CheckAll(this);"
/>
</HeaderTemplate>
<FooterTemplate>
<asp:Button ID="btnDelete"
runat="server"
Text="Delete" OnClick="Button1_Click" OnClientClick="return DeleteConfirmation();"/>
</FooterTemplate>

Ali ORALPosted Nov 11, 2014, 7:11 AM
Nice job thx
johhn prathipPosted Apr 10, 2013, 6:47 AM
thanks yadav..
SairamPosted Aug 30, 2010, 3:16 AM
can u help me in getting the "selected row in datagrid to be loaded in details view"