简体   繁体   中英

How to access a user selected item from a dropdown list that is within a fieldset and a content template in asp.net using c#

I am fairly new to asp.net and I am having trouble with adding a role form the registration page. I am using the pre-made registration page that is given when you create a new website using asp.net framework 4. I have added this label and drop down list inside the here is the code inside the .aspx file:

<p>
    <%--This is for the user type--%>
    <asp:Label ID="UserTypeLabel" runat="server">What type of user are you? Please select from below. </asp:Label>
    <asp:DropDownList ID="DropDownList1" runat="server" 
     onselectedindexchanged="DropDownList1_SelectedIndexChanged">
    <asp:ListItem Value="0">Please select an item below...</asp:ListItem>
    <asp:ListItem Value="1">Builder</asp:ListItem>
    <asp:ListItem Value="2">Investor</asp:ListItem>
    <asp:ListItem Value="3">Other</asp:ListItem>
    </asp:DropDownList>
    <%--END USER TYPE--%>
</p>

Now I want to know what the user has selected and when I attempt to add code in the .aspx.cs file it does not seem to "see" the dropdown list. I have tried using the following to access:

1) registeruser.dropdownlist1.value (error message Error1 'System.Web.UI.WebControls.CreateUserWizard' does not contain a definition for 'dropdownlist1' and no extension method 'dropdownlist1' accepting a first argument of type)

2)dropdownlist1.value (error message the name dropdownlist1 does not exist in the current context)

Is there an include file that I need or is there a method to get the aspx.cs page to access the ddl? NOTE: the field set is contained within a and a and a not sure if that's important.

Not sure if this is what you expect, but you can create an event handler.

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
    var item =((DropDownList)sender).SelectedItem;
}

Not sure if code is correct but this is an idea.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM