Click here to Skip to main content
15,885,847 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have a DDL that is not data bound. It is made up with a list of things I have for the user to choose from. I am trying to get that value to populate into a textbox. How would I do this?

ASP.NET
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
                   onselectedindexchanged="DropDownList1_SelectedIndexChanged" Width="150px">
                   <asp:ListItem>Select Calendar</asp:ListItem>
                   <asp:ListItem>Semester</asp:ListItem>
                   <asp:ListItem>Quarter</asp:ListItem>
               </asp:DropDownList>


Code Behind
C#
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            //TextBoxCal.Text = ["Calendar"].ToString();
        }
Posted

1 solution

C#
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
    TextBoxCal.Text = DropDownList1.SelectedValue;
}
 
Share this answer
 
Comments
Computer Wiz99 24-Jul-15 10:20am    
Thanks that worked great!!!
Computer Wiz99 24-Jul-15 10:28am    
When the user selects a value in the DDL the textbox populates but the Label I have in place does not change until the user selects "Select Calendar" then the user can select a value and the Label changes. Why does this happen? How can I correct it?
F-ES Sitecore 24-Jul-15 10:32am    
Do the label update in the SelectedIndexChanged event as well.
Computer Wiz99 24-Jul-15 10:34am    
Okay, So I should remove it from Page_Load and put it in the SelectedIndexChanged event?
F-ES Sitecore 24-Jul-15 10:36am    
If you want the label to update when the dropdown changes then the changed event is the best place for it.

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