2 回答

TA貢獻1829條經(jīng)驗 獲得超7個贊
您使用ASPxGridViewRowEventArgs.KeyValue屬性獲取行 ID,然后從數(shù)據(jù)庫中刪除特定記錄。您必須指定 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
}

TA貢獻1828條經(jīng)驗 獲得超3個贊
從 datagridview 中刪除行不會影響數(shù)據(jù)庫中的數(shù)據(jù)表。您需要編寫一個查詢來從數(shù)據(jù)庫中刪除數(shù)據(jù)。
如果您使用 sql、mysql 等,請嘗試獲取鏈接按鈕事件上的主鍵或任何唯一列并執(zhí)行刪除行的命令。
在你的點擊事件中類似這樣的東西來獲取傳遞給數(shù)據(jù)庫的 ID
int MyID = int.Parse(yourDataGridView.SelectedRows[0].Cells[0].Value.ToString());
以及要從數(shù)據(jù)庫中刪除的查詢
delete from MyTable
where p_Key = MyID;
- 2 回答
- 0 關(guān)注
- 323 瀏覽
添加回答
舉報