IntroductionAdd the below code for adding the check boxes in your GridView.This is very simple snippet at the same time.very useful. Html Code <asp:TemplateField HeaderText="Select">
<ItemStyle HorizontalAlign="Center" Width="5%" />
<HeaderStyle width="5%" HorizontalAlign="Center"/>
<ItemTemplate >
<asp:CheckBox Enabled="true" ID="chkBox" runat="server"/>
</ItemTemplate>
</asp:TemplateField> Then Write the below code in button click event C# Code foreach (GridViewRow row in gridview.Rows)
{
CheckBox CheckBox1 = (CheckBox)row.FindControl("chkBox");
//Checking for the checkbox is checked or not
if (CheckBox1.Checked == true)
{
ID= gridview.DataKeys[row.RowIndex].Value.ToString();
}
}Hopes help and Thank you. |