Delete a Datalist String with Multiple Primary Keys

I have a datalist with OnDeleteCommand = "Delete_Command".

I want to delete an entry with several primary keys, but I do not know how to access it from the Delete_Command event.

If I use DataKeyField, I will be limited to only one key. Any workarounds for this?

+4
source share
2 answers

You can access all 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"]... } 
+1
source

Oh sorry, I missed it.

AFAIK by default there is no such possibility. Perhaps you can create a composite key from your primary keys, for example

Key1UnderscoreKey2UnderscoreKey3

and separate it in the event handler. So, this is a multi-user key handler for a DataList :-)

Edit: The underscore is lost during formatting, it is replaced with italic text. So instead of using the word underscore, use real underscores

0
source

Source: https://habr.com/ru/post/1276389/


All Articles