[英]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. 我对asp.net相当陌生,无法在注册页面添加角色。 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:
我使用的是使用asp.net框架4创建新网站时提供的预制注册页面。我已经在.aspx文件中的代码内添加了此标签和下拉列表:
<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. 现在,我想知道用户选择了什么,并且当我尝试在.aspx.cs文件中添加代码时,它似乎没有“看到”下拉列表。 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) 1)registeruser.dropdownlist1.value(错误消息Error1'System.Web.UI.WebControls.CreateUserWizard'不包含'dropdownlist1'的定义,并且没有扩展方法'dropdownlist1'接受第一个类型的参数)
2)dropdownlist1.value (error message the name dropdownlist1 does not exist in the current context) 2)dropdownlist1.value(错误消息名称dropdownlist1在当前上下文中不存在)
Is there an include file that I need or is there a method to get the aspx.cs page to access the ddl? 是否有我需要的包含文件,或者有获取aspx.cs页以访问ddl的方法? NOTE: the field set is contained within a and a and a not sure if that's important.
注意:字段集包含在a和a中,并且不确定是否重要。
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. 不知道代码是否正确,但这是一个主意。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.