如何获取下拉列表中对应的所选项目的ID [英] how to obtain id of corressponding selected item in drop down list

查看:68
本文介绍了如何获取下拉列表中对应的所选项目的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的申请中,我想要一个选定大学名称的大学编号.大学名称是从下拉列表中选择的.如何获取与所选大学名称相对应的大学编号.请在sql server中查询以获取此名称?
谢谢.

In my application,I want a college id of selected college name. The college name is selected from drop down list. How can i get college id of corressponding selected college name.Please give me query in sql server to obtain this?
Thanks.

推荐答案

这个问题的最佳答案比我详细介绍的要花更多的时间.如果您需要此类信息,则用于填充列表的存储过程应该已经返回了所需的信息.那时,您只需要绑定列表(使用最适当/所需的绑定机制),然后在列表中选择该项目时,就可以从绑定的对象中获取ID.

抱歉,我没有时间发布示例代码,但是由于您是一名程序员,所以上面的说明应该确实可以帮助您入门.
The best answer for this question takes more time than I have available in detail. If you need this kind of info, the stored proc you used to populate the list should already return the desired info. At that point, you merely bind the list (with the most appropriate/desired binding mechanism), and when the item is selected in the list, you can get the id from the bound object.

Sorry, I don''t have time to post sample code, but since you''re a programmer, the instructions above should really be enough to get you started.


string sql = string.Format(select * from department"

DataTable tab = new DataTable();
open_con();
SqlDataAdapter adp = new SqlDataAdapter(sql, con);
adp.Fill(tab);
close_con();

Dropdepartment.DataSource = tab;
Dropdepartment.DataTextField = "Department_name";
Dropdepartment.DataValueField = "DepartmentID";
Dropdepartment.DataBind();



然后在按钮单击事件 u 中,您可以编写
字符串colleageID = Dropdepartment.SelectedValue;



then in button click event u you can write
string colleageID =Dropdepartment.SelectedValue;


这篇关于如何获取下拉列表中对应的所选项目的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆