Suppose i have a dataset object containing a data table from my database i want to list out the data in dropdownlist which should display the content but when user selects an item it should return id of the selected data.
Consider this scenario
1. In a dataset A table named XXX has three fields named id(primary key), dataName, dataType
2.In my application i want to use a drop down list where the user is shown only datanames in the drop down list and when he selects a particular dataname it's corresponding id should be returned to the application .
3. What i don't know is how to bind the datasource (here dataset) to a drop downlist and how to list out the desired field and also how to get only id of the specific data please help...
then use the OnSelectedIndexChanged event of your dropdown, in the code for this event you can use yourDropDownList.SelectedValue to get the selected id
then use the OnSelectedIndexChanged event of your dropdown, in the code for this event you can use yourDropDownList.SelectedValue to get the selected id
Agree!But if you want to raise the event of dropdownlist,please don't forget to set AutoPostBack=true:-)
boddu.sudhir
0 Points
1 Post
Using Dropdownlist with datasource
Jun 20, 2012 11:41 AM|LINK
Suppose i have a dataset object containing a data table from my database i want to list out the data in dropdownlist which should display the content but when user selects an item it should return id of the selected data.
Consider this scenario
1. In a dataset A table named XXX has three fields named id(primary key), dataName, dataType
2.In my application i want to use a drop down list where the user is shown only datanames in the drop down list and when he selects a particular dataname it's corresponding id should be returned to the application .
3. What i don't know is how to bind the datasource (here dataset) to a drop downlist and how to list out the desired field and also how to get only id of the specific data please help...
Dr. Acula
Participant
1441 Points
319 Posts
Re: Using Dropdownlist with datasource
Jun 20, 2012 12:05 PM|LINK
first bind your datasource to your dropdownlist
then use the OnSelectedIndexChanged event of your dropdown, in the code for this event you can use yourDropDownList.SelectedValue to get the selected id
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Using Dropdownlist with datasource
Jun 21, 2012 02:00 AM|LINK
Agree!But if you want to raise the event of dropdownlist,please don't forget to set AutoPostBack=true:-)
Thanks and Reguards!