1

我创建了一个带有下拉列表的 asp.net Web 应用程序 (VB),其中包含服务器上页面的 url 列表。我是asp和VB的新手。我研究了不同的论坛以寻求解决方案,并决定为我的问题寻求特定的解决方案。

分解。- 我有一个完全构建的页面 - 此页面每两小时存档一次到存档文件夹(使用 vbs) - 使用文件名和 url 生成 XML 文件(使用 VBS) - XMl 是 DDL 的数据源。

我想要完成的是,当用户单击 DDL 中的项目时,他们应该被定向到该页面。

在遵循其他论坛和这个论坛的一些建议之后,似乎没有任何效果。

一旦我们深入研究这一点,我们将对任何混淆有更好的理解。

  • 代码隐藏是 VB,所以我更喜欢那种语言。

ASPX 页面

enter code here

<%@ Page Title="Home" Language="vb" MasterPageFile="~/Site.Master"     AutoEventWireup="false"CodeBehind="Default.aspx.vb" Inherits="Status._Default" %>     <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"></asp:Content><asp:Content ID="BodyContent"runat="server" ContentPlaceHolderID="MainContent"></asp:Content>


<asp:XmlDataSource ID="statsXML" 
    runat="server" DataFile="~/Archive/Stats.xml" 
    XPath="Elements/Element" /> 
<asp:DropDownList ID="DropDownList1" runat="server" 
     DataSourceID="statsXML"
     DataTextField="Name" 
     DataValueField="Value" 
     AutoPostBack="True" 
     CssClass="rightCol"  />
<br />
<p>

    <asp:Table ID="Table1" runat="server" GridLines="Horizontal" Width="100%">
        <asp:TableRow BorderWidth="1" BorderStyle="Solid" Font-Size="12">
            <asp:TableCell HorizontalAlign="Center" Text="Text here" BorderStyle="Solid" BorderWidth="0"
                ForeColor="White" BackColor="#006699"></asp:TableCell>
        </asp:TableRow>
        <asp:TableRow BorderWidth="1" BorderStyle="Solid" Font-Size="12">
            <asp:TableCell HorizontalAlign="Center" Text="Text here" BorderStyle="Solid"
                BorderWidth="0" ForeColor="White" BackColor="#006699"></asp:TableCell>
        </asp:TableRow>
    </asp:Table>
    <br />
</p>
<asp:Table ID="Table2" runat="server" GridLines="both" Width="100%" BorderColor="Black">
    <asp:TableRow BorderWidth="1" BorderStyle="Solid" Font-Size="12" BorderColor="Black">
        <asp:TableCell Width="50%" HorizontalAlign="Center" Text="Enviroment" BorderStyle="Solid" BorderWidth="1"
            ForeColor="White" BackColor="#006699" BorderColor="Black"></asp:TableCell>
        <asp:TableCell Width="50%" HorizontalAlign="Center" Text="State" BorderStyle="Solid"
            BorderWidth="1" ForeColor="White" BackColor="#006699" BorderColor="Black"></asp:TableCell>
    </asp:TableRow>
        </asp:Table>`

代码隐藏

Public Class webform
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'If Not Page.IsPostBack Then

        'End If
        'If Page.IsPostBack Then
        '    ' Response.Redirect(Me.DropDownList1.SelectedValue)
        ' End If
    End Sub

    Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, 
                                                     ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged    

        Response.Redirect(DropDownList1.SelectedItem.Value)

    End Sub

End Class
4

2 回答 2

0

你要做的是首先设置AutoPostbackTrueDropDownList.

<asp:DropDownList ID="myDropDownlist" runat="server" AutoPostback="True" />

之后,您应该能够在代码隐藏中处理SelectedIndexChanged事件DropDownList

Protected Sub myDropDownList_SelectedIndexChanged(sender As Object, e As EventArgs) Handles myDropDownList.SelectedIndexChanged

   ' Lookup the selected item and redirect here
   ' (This assumes that you've bound your URL to redirect to the value of the item,
   ' and not the display text.  Use SelectedItem.Text if the URL is being displayed
   Response.Redirect(myDropDownList.SelectedItem.Value)

End Sub
于 2013-06-04T20:57:53.483 回答
0

尝试这个

 Public Class WebForm1
        Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Private Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownList1.SelectedIndexChanged
        Response.Redirect(DropDownList1.SelectedItem.Text)
    End Sub
 End Class
于 2013-06-04T21:06:08.900 回答