网格表有5行,由数据库填充
如果我们想删除它上面的内容。
创建一个datatableTemp,在gridView上删除后,它也将删除一个表Temp 之后,它将通过tableTemp填充GridView。
//========Get datatable from database.
dtTempGrdBlockForDeviceByRole = Cls_BLOCKS.getDataTable_WriteField();
grdBlockForDeviceByRole = Cls_BLOCKS.getDataTable_WriteField();
for (int x = 0; x < grdBlockForDeviceByRole.Rows.Count; x++)
{
CheckBox chk = grdBlockForDeviceByRole.Rows[x].FindControl("ckDelete") as CheckBox;
string txtD = grdBlockForDeviceByRole.Rows[x].Cells[0].Text;
if (chk.Checked)
{
//If choice
//What should we do in here?
}
}
grdBlockForDeviceByRole.DataSource = dtTempGrdBlockForDeviceByRole;
grdBlockForDeviceByRole.DataBind();
你可以帮帮我吗?
答案 0 :(得分:1)
您可以按如下方式使用代码。
dtTempGrdBlockForDeviceByRole = Cls_BLOCKS.getDataTable_WriteField();
grdBlockForDeviceByRole = Cls_BLOCKS.getDataTable_WriteField();
for (int x = 0; x < grdBlockForDeviceByRole.Rows.Count; x++)
{
CheckBox chk = grdBlockForDeviceByRole.Rows[x].FindControl("ckDelete") as CheckBox;
string txtD = grdBlockForDeviceByRole.Rows[x].Cells[0].Text;
if (chk.Checked)
{
dtTempGrdBlockForDeviceByRole.Rows.RemoveAt(x);
}
}
grdBlockForDeviceByRole.DataSource = dtTempGrdBlockForDeviceByRole;
grdBlockForDeviceByRole.DataBind();
由于