I have a datalist with a OnDeleteCommand="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.
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]
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"]...
}
Oh, sorry, I missed it.
AFAIK there is no such a possibility by default. Maybe you can create a composite key from your primary keys, like
Key1UnderscoreKey2UnderscoreKey3
and split it in the event handler. So this is a DIY multi-key handler for DataList :-)
Edit: The underscore got lost during format, it replaces with italic text. So instead of "underscore" word use real underscores
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.