win  鼠标用dtatgird自带的按钮选中一行 用Button按钮来删除该行

解决方案 »

  1.   

    DataTableName.Rows[DataGridName.CurrentRowIndex].Delete();
      

  2.   

    cpp2017(慕白兄) 
    DataTableName是什么啊 我用datagird来代替它说不行
      

  3.   

    DelData(Convert.ToInt32(dataGrid1[dataGrid1.CurrentCell.RowNumber,0]));
    新建一个函数,然后获取你所选择的行的ID号,然后根据该ID号删除这一行,把ID号作为参数传递给函数DelData();
      

  4.   

    // .aspx
    <asp:datagrid ...
    <columns>
    <asp:templatecolumn>
    <itemtemplate>
    <asp:button CommandName=Delete CommandArgument=<%# Eval("主键列") %> ...
    // .aspx.cs... _DeleteCommand(...
    {
        object key = e.CommandArgument;
        // 你的具体删除代码 
    }
      

  5.   

    问题是获取该ID怎么获取  对Datagird不懂  我是菜鸟
      

  6.   

    老兄 那是web的代码 我要的是win的
      

  7.   

    我借cpp2017(慕白兄) 老兄的代码
    DataTableName.Rows[DataGridName.CurrentRowIndex].Delete();
    DataTableName//表名,DataGrid是绑定在表上的,或者查询语句返回的数据集(和临时表性质一样)
    DataGridName//DataGrid控件名,
    DataGridName.CurrentRowIndex//数据在表中行数索引
    这样做是用DataAdapter把数据填充到DataSet的表中 控件再绑定表
    最后要记得调用DataAdapter.Update();
    把修改的数据更新到数据库
      

  8.   

    Convert.ToInt32(dataGrid1[dataGrid1.CurrentCell.RowNumber,0])
    这一句就是获得ID值啊
      

  9.   

    private void dg1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) 

    //删除确认             
    LinkButton delBttn = (LinkButton) e.Item.Cells[4].Controls[0]; 
    delBttn.Attributes.Add("onclick","javascript:return confirm('确定删除?');");  e.Item.Attributes.Add("onmouseover","tdOver(this)");
    e.Item.Attributes.Add("onmouseout","tdOut(this)");
    }}private void dg1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
    string id=e.Item.Cells [0].Text.Trim ();//获取员工编号 string sqlstr="delete tab_backip where id='"+id+"'";
    data1.moddata (sqlstr);
    Response.Redirect ("backip_q.aspx");}