Datalist - How to Know ID From Underlying DB

V

Verde

Suppose I load a DataList up with a bunch of records from an underlying
Database. The DataList shows an Edit and a Delete button. Each record in
the database has a unique Integer ID value.

Now, during PostBack processing, how I (my code) know what the ID value is
for any given row shown in the DataList?

For example, I want to delete a record from the underlying database. I view
the Datalist in the browser, then click the Delete button. How can the
PostBack processing logic (in the MyDataList_ItemCommand() event procedure)
"know" the ID value for the row to be deleted - so it deletes the correct
row from the underlying database?

Note: e.Item.UniqueID is of no help here because that's the ASP.NET-assigned
ID - not the ID from the underlying database.

Thanks
 
B

Brock Allen

The DataList has a DataKeyField property that you set to be the PK column
from the data source.
 
B

Brock Allen

The DataList has a DataKeyField property that you set to be the PK
column from the data source.

Sorry, and to finish my thought in you ItemCommand event handler do this:

string pk = (string)_dataList.DataKeys[e.Item.ItemIndex];
 
V

Verde

Thanks Brock.


Brock Allen said:
The DataList has a DataKeyField property that you set to be the PK
column from the data source.

Sorry, and to finish my thought in you ItemCommand event handler do this:

string pk = (string)_dataList.DataKeys[e.Item.ItemIndex];
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top