I finally got that working. It was simple as I expected just that I didn't put much effort. This is what I did: User does the required edits (unchecking the checkbox for not received and editing the exact received quantity) an select 'Save'. On Save button click, I get the old data which was saved in ViewState into a datatable. Now I compare the GridView values to the values in DataTale (old values). If it has changed, I edit the value in the datatable. This changes the RowState of that row in the datatable. The code seems like this:
DataTable dtChallanDtl = new DataTable();
dtChallanDtl = (DataTable)ViewState["ChallanDtl"];
int i = 0;
int ChallanRcvd = 1;
foreach (GridViewRow r in gvChallanDtl.Rows)
{
CheckBox chk = (CheckBox)r.FindControl("CheckSelect");
TextBox txt = (TextBox)r.FindControl("txtRecvQty");
if (chk.Checked == true)
{
dtChallanDtl.Rows[i]["Received"] = 1;
}
else
{
ChallanRcvd = 2;
}
if (dtChallanDtl.Rows[i]["RecvQty"].ToString() != txt.Text)
{
dtChallanDtl.Rows[i]["RecvQty"] = txt.Text;
dtChallanDtl.Rows[i]["Received"] = 2;
ChallanRcvd = 2;
}
i++;
}
Here, the variable 'ChallanRcvd' represents the database column which stores the received status of the challan. 0-not received, 1-received, 2-partailly received. Now I do a bulk update using SqlDataAdapter's Update method. The important things here are: SqlDataAdapterObj.UpdateBatchSize = 4; //how many records need to be updated in each batch. SqlCommandObj.UpdatedRowSource = UpdateRowSource.None; //how command results are applied to the datarow. After all parameters are supplied, call SqlDataAdapterObj.Update(dtChallanDtl); I posted this question here because I couldn't find any example on bulk edit using GridView bound to a datatable. I hope it helps someone. Regards Test