dropdownlist没有将所选值传递给字符串变量 [英] dropdownlist not passing selected value to string variable

查看:62
本文介绍了dropdownlist没有将所选值传递给字符串变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我有一个dropdownlist,在页面加载时我绑定到数据表的问题是,当我从下拉列表中选择一个值时,它没有将其分配给变量
我也尝试过使用dropdowlistuser.selectedvalue,它会一直显示名字,而不显示我选择的任何内容

任何帮助将不胜感激



HI everyone I hava dropdownlist which i bind to a datatable when page loads my problem is when I select a value from the dropdown list it does not assign it to the variable
i have also tried using dropdowlistuser.selectedvalue it keeps displaying the first name and not anything i choose

any help would be apreciated



<asp:DropDownList ID="DropDownListUser" runat="server" Width ="153px" Height ="22px" DataValueField="User_Name" DataTextField="User_Name" OnSelectedIndexChanged="selection_changed" AutoPostBack ="true" EnableViewState ="true">





protected void selection_changed(object sender, EventArgs e)
    {
        string selUserName = DropDownListUser.SelectedItem.Text;
        lblWelcomeText.Text = "Welcome " + selUserName;


}

推荐答案



正如您所说的,您将在页面加载事件中限制下拉列表.回发事件后,您的下拉列表将丢失边界信息.

您需要确保您的下拉列表在pageload事件中反弹吗? (如果您指定了IsPostBack条件,则代码将仅首次绑定您的下拉列表)

我看不到您的代码有任何其他问题.

编辑
还要检查SelectedIndex.您正在获得什么价值?

让我知道您是否还有任何问题.
Hi,

As you said that you are bounding your dropdownlist in the page load event. After postback event your dropdown will lost the bounding information.

you need to make sure your dropdownlist is rebound in pageload event ? (if you have specified IsPostBack condition then code will bound your dropdownlist for first time only)

i can''t see any other issue with your code.

Edit
Also check with SelectedIndex. What value you are getting ?

Let me know if you still have any issue.


这篇关于dropdownlist没有将所选值传递给字符串变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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