Consider a scenario where you want to delete all the selected records in the gridview.
First of all , a primary key has to be set for each record which can be done by declaratively setting datakeynames property in the gridview tag.
Loop through the GridViewRows as shown in the code snippet below:
CheckBox chk = null;
StringBuilder sweepStakeIds = new StringBuilder();
int index = 0;
foreach (GridViewRow row in grdSweepStakes.Rows)
{
chk = (CheckBox)row.FindControl("chkSelect");
if (chk.Checked)
{
sweepStakeIds.Append(grdSweepStakes.DataKeys[index].Value.ToString());
sweepStakeIds.Append(",");
index++;
} Here ids are passed as comma separated values to stored procedured where it is taken care by the logic inside the procedureinorder to reduce database talk by deleting all the records in one go.
No comments:
Post a Comment