tags:

views:

902

answers:

2

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?

Thank you

+1  A: 

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"]...
}
Biri
A: 

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

Biri