代码之家  ›  专栏  ›  技术社区  ›  Etienne

使用ASP.NET DropDownList项不工作-需要事件吗?

  •  0
  • Etienne  · 技术社区  · 15 年前

    我正在使用ASP.NET

    我有一个DropDownlist项目,在那里我有超链接作为值。在我的代码隐藏中,当用户选择“erate”项目时,我必须使用什么事件将其重定向到该URL?

    我的密码

       <asp:DropDownList ID="dropSelect" runat="server" Width="126px">
            <asp:ListItem>Please select</asp:ListItem>
            <asp:ListItem Value="http://www.erate.co.za">eRate</asp:ListItem>
        </asp:DropDownList>
    

    事先谢谢!!

    1 回复  |  直到 9 年前
        1
  •  3
  •   Dejan.S    15 年前

    将OnSelectedIndexChanged添加到下拉列表中,如下所示

    OnSelectedIndexChanged="dropSelect_OnSelectedIndexChanged"
    

    然后代码隐藏你可以这样做。

    protected void dropSelect_OnSelectedIndexChanged(object sender, EventArgs e)
        {
            Response.Redirect(dropSelect.SelectedValue);
        }
    

    你可以做一些额外的空检查,但这是你可以使用的基本思想