private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
using (SystemDataAccess da = new SystemDataAccess())
{
da.Get_SqlCmd.CommandText="delete from PubMessage  where id = @id";
da.Get_SqlCmdParam.Add("@id",);
da.Get_SqlCmd.ExecuteNonQuery();
DataGrid1.DataBind();
                           }
                  }
怎么从列表中取到这个ID的值咯

解决方案 »

  1.   

    可以在datagrid中方一个隐藏列,用来存放ID值
      

  2.   

    <asp:DataGrid datakeyfield="id" ...
    private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
    using (SystemDataAccess da = new SystemDataAccess())
    {
    da.Get_SqlCmd.CommandText="delete from PubMessage  where id = @id";
    da.Get_SqlCmdParam.Add("@id", DataGrid1.DataKeys[e.Item.Index].ToString());
    da.Get_SqlCmd.ExecuteNonQuery();
                                        BindGrid();//需要重新绑定数据
    //DataGrid1.DataBind();
                               }
                      }
      

  3.   

    ID的值我放到了DataGrid1里面了,它在第一行它是可见的。
    我现在就是要写删除
    不知道怎么把ID的值取出来
      

  4.   

    设置DataGrid1的列集中第0列的可见性为false
      

  5.   

    天堂客 为什么要把第0列的可见性设为false咯 这和取ID值有关吗
      

  6.   

    你表中ID是不是第一列?
    在DataGrid中你不想使ID列显示?
    那就把这列在绑定后设置可见性为假,就不可见了列还在所以用列号可取值
      

  7.   

    那这个ID的值就是e.Item.Cells[0].Text呀
      

  8.   


    是这样写吗
    da.Get_SqlCmdParam.Add("@id", e.Item.Cells[0].Text);