根据下拉选择填充文本框 [英] Populating a textbox based on drop down selection

查看:79
本文介绍了根据下拉选择填充文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用基于下拉选择的数据库值填充文本框

How should i populate the textbox with the database values based on dropdown selection

推荐答案

使用 SelectedIndesxChanged 下拉列表事件。


如果你想根据你的选择从数据库中检索一些值,你可以使用下拉框中的''AutoPostBack''属性来强制选择项目时的回发事件:



If you want to retrieve some values from the DB based on your selection, you can use the ''AutoPostBack'' attribute in your drop down box to force a postback event when the item is selected:

<asp:dropdownlist cssclass="myClass" id="myDropDown" autopostback="true" runat="server" />





然后在你的代码背后,您可以访问选择的项目:





And then in your code behind, you can access the item selected with:

int mySelectedIndex = myDropDown.SelectedIndex;



或:


or:

String mySelectedValue = myDropDown.SelectedValue;





...做你的数据库的东西,然后当你想填充你的文本框时:





...do your database stuff, and then when you want to populate your text box:

myTextBox.Text = "myNewValue";


这篇关于根据下拉选择填充文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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