简体   繁体   English

如何使用c#从asp.net中的字段集和内容模板中的下拉列表访问用户选择的项目

[英]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.

相关问题 使用用户控件的ASP.NET C#下拉列表 - ASP.NET C# Dropdown List using User Control 如何从下拉列表中获取选定的值C#ASP.NET - How to Get Selected Value from Dropdown List C# ASP.NET 如何在ASP.NET MVC C#中使用LinQ to SQL对从数据库中选择的项目进行排序 - How to sort item selected from database using LinQ to SQL in asp.net mvc c# 如何传递asp.net下拉选择项作为C#中存储过程的输入? - How to pass the asp.net dropdown selected item as an input to a stored procedure in c#? 使用asp.net C#获取下拉列表的选定索引 - Getting selected Index of dropdown using asp.net C# 如何使用 C# 从 ASP.NET 的母版页中更改内容页? - How to change the content page from within the masterpage in ASP.NET using C#? 如何根据从下拉列表中选择的内容(ASP.NET中的C#)更改标签的输出 - How can I change the output of a label, based on what's selected from a dropdown list (C# in ASP.NET) 使用c#DropDownList项目的asp.net未选中 - asp.net using c# DropDownList item not selected 如何在asp.net C#Web窗体应用程序中基于下拉列表的选定值填充文本框? - How to populate a textbox based on the selected value of a dropdown list in an asp.net c# web forms application? 如何更新下拉列表中的选定项asp.net c# - how to update a selected item in a dropdownlist asp.net c#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM