在屬性產生器中columns中新增一個刪除按鈕
然后在添加該DataGrid的Delete事件﹐在其中添加代碼
string str=((TextBox)e.items.cells[0].control[0]).Text.ToString();
取得要刪除的項﹐然后到數據庫中查找這條記錄﹐進行刪除﹐然后再重新對datagrid進行
數據綁定﹔
添加的話可以在數據庫中先增加一條記錄﹐然后再重新綁定到DataGrid就行了

解决方案 »

  1.   

    增加一行:
    private void addsub_Click(object sender, System.EventArgs e)
    {
    DataTable objDt=myTree.GetNodes(nodeid,true,-1);

    DataRow objDr=objDt.NewRow();//为子菜单列表添加一个新行,以放置新菜单
    objDr["id"]="0";
    objDr["text"]="请输入菜单名称";
    objDr["url"]="请输入菜单链接页面";
    objDt.Rows.InsertAt(objDr,0); subnodes.EditItemIndex=0;
    subnodes.DataSource=objDt.DefaultView;
    subnodes.DataBind(); this.BindListBox(subnodes,"allowdepartments",0);
    this.BindListBox(subnodes,"allowusers",0);}
      

  2.   

    -------------------------------------------
    DataRow objDr=objDt.NewRow();//为子菜单列表添加一个新行,以放置新菜单
    objDr["id"]="0";
    objDr["text"]="请输入菜单名称";
    objDr["url"]="请输入菜单链接页面";
    objDt.Rows.InsertAt(objDr,0); subnodes.EditItemIndex=0;
    subnodes.DataSource=objDt.DefaultView;
    subnodes.DataBind();
    ----------------------------------
    就这是有用的代码,我是直接从我的程序里COPY出来的
      

  3.   

    Private Sub dg_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dg.DeleteCommand
            Dim i As Integer
            For i = 0 To dg.Items.Count - 1
                Dim cb As CheckBox = CType(dg.Items(i).FindControl("chkbox"), CheckBox)
                If cb.Checked = True Then
                                  Dim cm As New SqlDataAdapter("delete * from userinfo where id=@id", l.conn)
               cm.SelectCommand.Parameters.Add("@id", SqlDbType.Int).Value = dg.Items(0).FindControl("id")
                cm.SelectCommand.ExecuteNonQuery()
                dg.DataBind()
                End If
    next    End Sub
      

  4.   

    DataGrid的最终显示结果一般是由与它帮定的数据源决定的,比如:DataTable,DataSet
    你对这些数据源进行添加删除操作就可以了,最后别忘了重新帮定一遍
      

  5.   

    还有,iyond(伊飏) 得方法改成VB怎么改?