-1

一个网格表有 5 行,由数据库填充。
如果我们想删除 somerow 就可以了。

解决方案:

创建一个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();

你能帮帮我吗?

4

1 回答 1

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();

谢谢

于 2013-02-25T09:04:08.620 回答