aspxgridview 行命令删除

我想 aspxgridview 在 row 命令中删除该行。


protected void BootstrapGridView1_RowCommand(object sender, DevExpress.Web.ASPxGridViewRowCommandEventArgs e)

{

    if (this.IsPostBack)

    {

        if (e.CommandArgs.CommandName == "delete")

        {

           ROW DELETE CODE

        }


    }

}


BIG阳
浏览 299回答 2
2回答

千巷猫影

您使用ASPxGridViewRowEventArgs.KeyValue属性获取行 ID,然后从数据库中删除特定记录。您必须指定 KeyFieldName="keyfieldcolumnname" 才能在 RowCommand 事件中获取键列值。该ASPxGridViewRowEventArgs.KeyValue属性提供能力通过一个键值来获得一个ID值。例子:<dxwgv:ASPxGridView ID="gv" runat="server" AutoGenerateColumns="False"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; KeyFieldName="ID"...protected void gv_RowCommand(object sender, ASPxGridViewRowCommandEventArgs e) {&nbsp; &nbsp; ASPxGridView grid = (ASPxGridView)sender;&nbsp; &nbsp; object id = e.KeyValue;&nbsp; &nbsp;//Delete record using data adapter or some other ORM&nbsp;&nbsp; &nbsp;// Delete from users where userid=id}

子衿沉夜

从 datagridview 中删除行不会影响数据库中的数据表。您需要编写一个查询来从数据库中删除数据。如果您使用 sql、mysql 等,请尝试获取链接按钮事件上的主键或任何唯一列并执行删除行的命令。在你的点击事件中类似这样的东西来获取传递给数据库的 IDint MyID = int.Parse(yourDataGridView.SelectedRows[0].Cells[0].Value.ToString());以及要从数据库中删除的查询delete from MyTablewhere p_Key = MyID;
打开App,查看更多内容
随时随地看视频慕课网APP