this is the code i have used in one of my page. hope this helps.
I have used list arrays and sessions for doing this. u can use viewstate also if there is no page navigation.
DiabeticFields objDiabeticFields = new DiabeticFields();
List<DiabeticFields> diabList = new List<DiabeticFields>();
I have used one button
cmdDelete
. After clicking on this button the following event will be fired
protected void cmdDelete_Click(object sender, EventArgs e)
{
diabList = (List<DiabeticFields>)(Session["DiabObject"]);
CheckBox chk = new CheckBox();
foreach (GridViewRow gvr in grdDocOrders.Rows)
{
chk = (CheckBox)(gvr.Cells[0].FindControl("chkSelect"));
if (chk.Checked == true)
{
diabList.RemoveAt(gvr.RowIndex);
}
Session["DiabObject"] = diabList;
if (diabList != null)
{
grdDocOrders.DataSource = diabList;
grdDocOrders.DataBind();
}
else
{
emptyGridFix();
}
}
}
the
DiabObject
contains all the rows of the gridview.
There is no need to present these rows in database..