You must Sign In to post a response.
  • Category: .NET

    How to check selected same value in gridview using check box in c#

    i have gridview as follows

    asp:gridview ID="GridView1" runat="server"
    <asp:TemplateField HeaderText="Select Data">
    <asp:CheckBox ID="chkSelect" runat="server"/>

    Selectdata Slipno Product

    10 NPK
    10 NPK
    12 UREE
    15 ENGRA

    for example, if i select the slip no value 10 using check box, similarly slip no 10 in the second row is automatically checked in the gridview.

    My code as follows

    GridViewRow selectedRow = (sender as CheckBox).NamingContainer as GridViewRow;
    string selectedName = selectedRow.Cells[1].Text;
    DataTable dt = ViewState["Data"] as DataTable;

    foreach (GridViewRow gvrow in GridView1.Rows)
    ViewState["Data"] = dt;
    CheckBox chk = (CheckBox)gvrow.FindControl("chkSelect");
    if (chk != null & chk.Checked)
    int duplicateCount = dt.Select("Slipno='" + selectedName + "'").Length;
    if (duplicateCount > 0)
    for (int i = 0; i < dt.Rows.Count; i++)
    if (dt.Rows[i]["Slipno"].ToString() == selectedName)
    dt.Rows[i]["Select Data"] = true;

    When i run the above code shows error as follows

    Column 'Select Data' does not belong to table Table1.

    how to solve the above error.
  • #769950
    AS it says 'Select Data' column name is wrong in DataTable dt. you can try by giving index of column

    e.g. dt.Rows[i][3] = true; //if your column index for Select Data is 3

  • Sign In to post your comments