How can I update GridView rows on pageindexchanging if row template fields have changed?

410 Views Asked by At

I have the following onclick event for updating gridview rows that have changed. I need to update the rows if the user changes page index without clicking the update button first.

protected void btnUpdate_Click(object sender, EventArgs e)
{
    foreach (GridViewRow row in GridView1.Rows)
    {
        CheckBox chk = (CheckBox)row.FindControl("chkSelect");
        if (chk.Checked)
            GridView1.UpdateRow(row.RowIndex, false);
    }
    btnUpdate.Enabled = false;
    BindToGrid();
}

Any help is greatly appreaciated.

1

There are 1 best solutions below

0
On

Simple you can do is, create a method that will extract the fields and save the values to db and call it in both events

  1. Onclick, &
  2. PageIndexChanging