当从asp.net中的下拉列表中选择项目时,如何在文本框中显示desciption [英] how do display desciption in textbox when item selected from dropdownlist in asp.net

查看:72
本文介绍了当从asp.net中的下拉列表中选择项目时,如何在文本框中显示desciption的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,



在我的网页上我有下拉列表和一个文本框。



在数据库中我有一个表(Departments),在这里我有字段Dept_code,Dept_desc

这些dept_code和Dept_desc填入数据库,里面有数据。



在下拉列表中,我有部门代码列表。这些部门从数据库表中获取。



例如:在数据库中它存储如下

Dept_code - IT

Dept_desc - 信息技术。



现在,如果我从下拉列表中选择IT,自动Dept_desc必须显示在文本框中。



根据下拉值,它应该检索并填写文本框。



请帮助我谢谢。

hello frnds,

on my webpage i have dropdownlist and a textbox.

in database i have a table(Departments), in this i have fields as Dept_code, Dept_desc
These dept_code and Dept_desc are filled in database with data in it.

In dropdownlist i have list of department codes. these departments am taking from database table.

for example : in database it is stored like this
Dept_code - IT
Dept_desc - Information Technology.

Now, if i select IT from dropdownlist, automatically Dept_desc must display in Textbox.

Based upon dropdown value it should retrieve and filled in textbox.

Please help me thanks.

推荐答案





绑定数据库中的数据绑定dropdownlist.DisplayMember和dropdownlist.ValueMember,将displaymember绑定到dept_code,将valueMember绑定到dept_description。然后在dropdownlist selectedindexchanged事件中将textbox值设置为dropdownlist'的valuemember属性。



如果你不明白这一点,请给你的代码,我会指导你....
Hi,

While binding data from database bind the dropdownlist.DisplayMember and dropdownlist.ValueMember, bind the displaymember to dept_code and valueMember to dept_description. then on dropdownlist selectedindexchanged event set the textbox value to dropdownlist''s valuemember property.

If you don''t understand this, plz give your code , i will guide you....


如果你有dept_desc数据没有任何重复,那么你填写这样的下拉列表

值应该是dept_desc

文本应该是dept_code



这样它就会向用户显示dept_code。但如果下拉列表值有任何重复,这可能会中断。因此,如果你的数据库返回不同的描述,那就没问题。



当用户更改下拉列表时,你可以为客户端onChange事件编写一个js函数并获取SelectedItem.Value然后将此值设置为文本框



如果desc不是唯一的,那么我认为你将不得不在数组中进行操作。您可以将所有这些dec保留在客户端数组中,并使用相同的索引填充到下拉列表中。然后使用下拉选择索引可以从数组中选择并显示到文本框



谢谢,

Siju Thomas。
If you have the dept_desc data is not having any duplicates then you populate the dropdownlist like this
value should be dept_desc
text should be dept_code

So that it will display dept_code to the user. But this may break if the dropdownlist values has got any duplicate. So if your DB returns distinct descriptions then this would be fine.

While user change the dropdown , you can write a js function for the client side onChange event and get the SelectedItem.Value and then set this value to the textbox

If the desc is not unique then I think you will have to manipulate in an array. You can keep all those dec in client array and with the same index it populate to the dropdown. Then using the dropdown selected index can pick from the array and show to the textbox

Thanks,
Siju Thomas.


这篇关于当从asp.net中的下拉列表中选择项目时,如何在文本框中显示desciption的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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