选择下拉列表值时以及如何获取相应选择项的ID [英] when select a dropdownlist value and how to get id for corresponding select item
本文介绍了选择下拉列表值时以及如何获取相应选择项的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我选择一个下拉列表值时,如何获取相应所选项目的ID?
例如
City Master : city_id :1 ,city_name :Chennai.
当我从下拉列表中选择Chennai时,我想从数据库中获取存储的city_id.
当我从列表中选择Chennai时,如何获取city_id?
When I select a dropdownlist value how do I get an id for corresponding selected item?
Eg.
City Master : city_id :1 ,city_name :Chennai.
When I select Chennai from the dropdown list, I want to get the stored city_id from the database.
How do I get city_id, when I select a Chennai from the list?
推荐答案
您可以将显示成员设置为城市名称,将值成员设置为id.然后,在选择时,使用SelectedValue进行处理.
You can set the display member as the city name and value meember as id. Then, on selection, use the SelectedValue for processing.
在下拉列表中,将数据字段设置为city_name,将值设置为id.然后,当您选择一个项目时,使用选定的值
in the drop down list set the data field to city_name and the value to the id.Then when you select an item use the selected value of the item.
<pre lang="midl">ddlCity.DataSource=dt;
ddlCity.DataTextField="CityName";
ddlCity.DataValueField = "CityId";
ddlCity.DataBind();</pre>
这篇关于选择下拉列表值时以及如何获取相应选择项的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文