【问题标题】:aspxgridview row command deleteaspxgridview 行命令删除
【发布时间】:2018-07-24 09:05:27
【问题描述】:

我想用 aspxgridview 删除行命令中的那一行。

protected void BootstrapGridView1_RowCommand(object sender, DevExpress.Web.ASPxGridViewRowCommandEventArgs e)
{
    if (this.IsPostBack)
    {
        if (e.CommandArgs.CommandName == "delete")
        {
           ROW DELETE CODE
        }

    }
}

【问题讨论】:

    标签: c# asp.net gridview devexpress


    【解决方案1】:

    您使用ASPxGridViewRowEventArgs.KeyValue 属性获取行ID,然后从数据库中删除特定记录。您必须指定 KeyFieldName="keyfieldcolumnname" 才能在 RowCommand 事件中获取键列值。

    ASPxGridViewRowEventArgs.KeyValue 属性提供了通过键值获取 ID 值的功能。

    例子:

    <dxwgv:ASPxGridView ID="gv" runat="server" AutoGenerateColumns="False"
                KeyFieldName="ID"...
    
    protected void gv_RowCommand(object sender, ASPxGridViewRowCommandEventArgs e) {
        ASPxGridView grid = (ASPxGridView)sender;
        object id = e.KeyValue;
       //Delete record using data adapter or some other ORM 
       // Delete from users where userid=id
    
    }
    

    参考资料:
    Fields value in ASPxGridView on Row Command
    ASPxGridView - How to implement CRUD operations with a custom data source
    CRUD Operation Using Stored Procedure In ASP.NET GridView Real Time

    【讨论】:

      【解决方案2】:

      从 datagridview 中删除行不会影响数据库中的数据表。你需要编写一个查询来从数据库中删除数据..

      如果您使用的是 sql、mysql 等,请尝试获取主键或链接按钮事件上的任何唯一列,并执行删除该行的命令。

      在您的点击事件中使用类似的方法来获取要传递给数据库的 ID

      int MyID = int.Parse(yourDataGridView.SelectedRows[0].Cells[0].Value.ToString());
      

      以及要从数据库中删除的查询

      delete from MyTable
      where p_Key = MyID;
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-01-13
        • 1970-01-01
        • 1970-01-01
        • 2017-07-31
        • 2011-09-18
        • 2017-08-23
        • 2018-04-09
        • 2021-12-11
        相关资源
        最近更新 更多