【问题标题】:Store in a variable the SelectedValue of a DropDownList then call it将 DropDownList 的 SelectedValue 存储在变量中,然后调用它
【发布时间】:2015-08-23 14:52:30
【问题描述】:

我正在向 asp.net 中的角色添加用户,但我想从下拉列表中获取所选角色。一个选项对我有用,但我需要实现两个选择 dropD 列表。

public partial class Register : Page
{
    protected void Selection_Change(object sender, EventArgs e)
    {
        var tr = TakeRole.SelectedValue; // store it in some variable
    }
    protected void CreateUser_Click(object sender, EventArgs e)

    {
       // code 
       if (result.Succeeded)
        {
           manager.AddToRole(user.Id, "SomeRoleName");
    }
}

在我的 aspx 上

        <asp:DropDownList id="TakeRole" AutoPostBack="True" OnSelectedIndexChanged="Selection_Change" runat="server">
          <asp:ListItem> Supplier </asp:ListItem>
          <asp:ListItem Selected="True"> Customer </asp:ListItem>
       </asp:DropDownList>

【问题讨论】:

标签: c# asp.net


【解决方案1】:

请在多选模式下使用列表框并将选择限制为 2 个项目。否则,您可以将下拉列表与 jQuery 一起使用。 如果您打算使用复选框列表,那么除了绑定源之外,检查将事件计数检查项更改为 2,如果选择了更多项,则会显示警报。

【讨论】:

  • 变量所在的范围,这就是我遇到的问题,我需要在 if 语句中使用它。就像我说的文字字符串正在工作,但我需要调用具有商店信息的 var。谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-01
  • 1970-01-01
  • 2019-07-14
  • 2013-05-23
  • 2017-03-04
  • 1970-01-01
相关资源
最近更新 更多