canuckconsulting
asked on
Retrieve field from SQLDataSource selected in bound DropDownList
I have an ASP.Net web application and have a drop down list which is bound to a SQLDataSource (SQL: SELECT ID, FileName, FileLocation FROM FILES). FileName is the display member in the list
When the user selects an item in the list I want to retrieve a the FileLocation and display it in a text box. How can I get this value from the selected item in the DataSource? I'm hoping I don't have to do another SQL query.
The user can change this displayed FileLocation and update it in the DB by clicking a Save button. Can I update the SQLDataSource directly?
When the user selects an item in the list I want to retrieve a the FileLocation and display it in a text box. How can I get this value from the selected item in the DataSource? I'm hoping I don't have to do another SQL query.
The user can change this displayed FileLocation and update it in the DB by clicking a Save button. Can I update the SQLDataSource directly?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you.
I was hoping for something like JamesBurger but this doesn't work in asp.net
I was hoping for something like JamesBurger but this doesn't work in asp.net
Simply cast DropDownList.SelectedItem to the type of the underlying data and you will have access to all its properties and methods. If the control is bound to a DataTable for instance, I could retrieve value of the City field in the selected row with the following:
(string)((DataRow) DropDownList.SelectedItem)