Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting the ID of a deleted record within a ListView

Status
Not open for further replies.

stinkybee

Programmer
May 15, 2001
218
GB
I have a list view that has the usual Delete, Edit and Insert options. However, when deleting a record I need to get the id of the record that is being deleted so I can make further changes to my database.

Can anyone supply some VB code that would allow me to do this.

Thanks

Web Development Manager
 
Howdy!

I usually work with GridViews instead of ListViews but I suspect it to be comparable:
Set the DataKey property of your ListView to your rec id field name, something like this:
Code:
<asp:ListView ID="ListView1" runat="server" DataKeyNames="recid">
And/or use a custom delete button like this:
Code:
<asp:ImageButton id="Delete" CommandName="rowDelete" CommandArgument='<%# Eval("uid") %>' runat="server" ImageUrl="~/delete.png" OnClientClick="return confirm('Warning: this will delete the entire record! Execute?');"/>
In your method that is called upon deletion, in my case "rowDelete", you can then get at the actual record if simply with
Code:
(string)e.CommandArgument

Cheers,
MakeItSo

“Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family.” (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.
 
I'd been searching for a solution for hours before posting this question so not sure why I couldn't find this before.
For some this is a frustrating experience but for me it's just Wednesday... [bigcheeks]
Glad I could nudge you in the right direction.

“Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family.” (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top