【问题标题】:Basic Website Web Form - How to link DropDownList to internal .aspx pages?基本网站 Web 表单 - 如何将 DropDownList 链接到内部 .aspx 页面?
【发布时间】:2015-11-13 12:07:32
【问题描述】:

我对使用 VB 比较陌生,正在尝试执行以下操作:

  1. 单击按钮时选择 DropDownList 项
  2. 将 DropDownList 项目链接到内部页面

我觉得这是基本的东西,但我很难用它。

这是正确的吗?

1 .

<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
<asp:ListItem Value="Answer.aspx">Answer</asp:ListItem>

2 。

<asp:Button ID="Button1" runat="server" Text="Button" onselectedindexchanged="DropDownList1_SelectedIndexChanged" />`

【问题讨论】:

  • “将 DropDownList 项目链接到内部页面” - 你想达到什么目的?
  • onselectedindexchanged 不是 Button 的属性

标签: asp.net vb.net dropdownlistfor .aspxauth


【解决方案1】:

您需要稍微更改您的代码才能实现此目的。首先,您不需要下拉列表中的 AutoPostback,除非您希望它在您选择新列表项时访问服务器。

单击按钮时,您将要删除

OnSelectedIndexChange="DropDownList1_SelectedIndexChanged"

并将其替换为按钮的 OnClick 事件。

OnClick = "Button1_Click"

您需要添加 vb 代码以重定向到新页面。我更喜欢 C#,但这应该可行。

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
    Dim LinkText as string
    LinkText = DropdownList1.SelectedItem.Value
    Response.Redirect(LinkText)
End Sub

【讨论】:

    【解决方案2】:

    你是想说,点击按钮后,它会通过在下拉列表中选择它是什么页面来转到另一个页面?如果我是正确的,这就是它的样子。

        Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
              Response.Redirect(DropDownList1.SelectedValue.ToString)
        End Sub
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-03
      • 1970-01-01
      相关资源
      最近更新 更多