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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Storing a hidden key value for each row in a datagrid 2

Status
Not open for further replies.

Billkamm

Programmer
Feb 9, 2006
74
US
I have a datagrid which displays some information and it also has a Delete button column.

My problem is I do not want to display the id (database key) associated with the record on the page, but I need this value to delete the record when the user clicks delete. Is there a way to store the key value somewhere so that when the user clicks delete I can delete it from the database. This key value is the only thing guarenteed to be unique, so I can't do a findbyvalue on a column with text in it.
 
You could just hide the column from the display so it still exists but isn't shown


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
sorry I'm an idiot lol. Thanks for your help. I think I'm going to try that
 
There's also a built-in property called "DataKeyField". If you set it to your key field, then the DataKeys property of the grid will be populated when you bind, and you'll be able to access it in your delete command event handler like:

Code:
myGrid.DataKeys[e.Item.ItemIndex]
 
I actually noticed that later on BoulderBum and decided it would make more logical sense to some reading the code to go that route and that is what I ended up doing. Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top