1
Hi,
Do refer below links
https://www.aspsnippets.com/Articles/524/GridView-with-CheckBox-Get-Selected-Rows-in-ASPNet/
https://www.c-sharpcorner.com/blogs/add-checkbox-in-asp-gridview-with-select-all-functionality
0
Hi,
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"><Columns><asp:TemplateField><ItemTemplate><asp:CheckBox ID="chkSelect" runat="server" /></ItemTemplate></asp:TemplateField><asp:BoundField DataField="ColumnName" HeaderText="Column Header" />
c#
bind data to the GridView on page load
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGrid();
}
}
private void BindGrid()
{
// Replace with your data source
var dataSource = GetData(); // Fetch your data here
GridView1.DataSource = dataSource;
GridView1.DataBind();
}
on select of check box
protected void btnSubmit_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox chkSelect = (CheckBox)row.FindControl("chkSelect");
if (chkSelect != null && chkSelect.Checked)
{
// Process the selected row
string selectedValue = row.Cells[1].Text; // Adjust index based on your columns
// Add your logic here
}
}
}