2
Answers

Grid multi checkbox

Sushant Torankar

Sushant Torankar

Nov 11
325
1

Hello,

I am binding Gridview with suppose 1000 records. I need to add checkbox infront of each row and user will check any checkbox they want and There should be common APPROVE button. On clicking on it, it should update status of CHECKED rows only

Test
Choose Reference Id Status Action
checkbox1 12345 Y APPROVE
checkbox2 78945 Y APPROVE
checkbox3 74185 Y APPROVE
checkbox4 85296 Y APPROVE

APPROVE

User can either update single record or multi-rows record (Checked row)

Thanks in Advance !

Answers (2)
1
Vishal Yelve

Vishal Yelve

108 17k 632k Nov 12

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
Sangeetha S

Sangeetha S

259 7.1k 313.4k Nov 14

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(&quot;chkSelect&quot;);
        if (chkSelect != null &amp;&amp; chkSelect.Checked)
        {
            // Process the selected row
            string selectedValue = row.Cells[1].Text; // Adjust index based on your columns
            // Add your logic here
        }
    }
}