本文介绍了删除与多个主键列Datalist中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个OnDeleteCommand =DELETE_COMMANDDataList控件。

I have a datalist with a OnDeleteCommand="Delete_Command".

我要删除多个主键的记录,但我不知道如何从DELETE_COMMAND事件访问它。

I want the delete a record with multiple primary Keys but I do not know how to access it from the Delete_Command event.

如果我使用DataKeyField我仅限于一个密钥。
这个任何变通办法?

If I use DataKeyField I'm limited to only one key.Any workarounds for this?

推荐答案

您可以访问所有的按键:

You can access all of the keys:

gridView.DataKeys[rowNum][dataKeyName]

其中的rowNum是e.RowIndex从gridView_RowDeleting事件处理程序,dataKeyName就是要拿到钥匙:

where rowNum is e.RowIndex from the gridView_RowDeleting event handler, and dataKeyName is the key you want to get:

<asp:GridView ID="gridView" runat="server" DataKeyNames="userid, id1, id2, id3" OnRowDeleting="gridView_RowDeleting">

protected void gridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
    gridView.DataKeys[e.RowIndex]["userid"]...
    gridView.DataKeys[e.RowIndex]["id1"]...
    gridView.DataKeys[e.RowIndex]["id2"]...
    gridView.DataKeys[e.RowIndex]["id3"]...
}

这篇关于删除与多个主键列Datalist中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 07:06