Click here to Skip to main content
15,889,838 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.NET
<asp:DropDownList ID="DropDownListUser" runat="server" Width ="153px" Height ="22px" DataValueField="User_Name" DataTextField="User_Name" OnSelectedIndexChanged="selection_changed" AutoPostBack ="true" EnableViewState ="true">


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

}
Posted
Updated 19-Nov-12 21:10pm
v2

1 solution

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.
 
Share this answer
 
v2
Comments
mrDivan 20-Nov-12 3:33am    
Thank you forgot about he postback thank you for your time spent helping me
AmitGajjar 20-Nov-12 3:35am    
Your always welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900