1

我有一个这样的列表框,

<asp:ListBox ID="ListBox1" runat="server" Height="175px" Width="213px">
            <asp:ListItem Value="all">All</asp:ListItem>
            <asp:ListItem Value="programmer">Computer Programmer</asp:ListItem>
            <asp:ListItem Value="itss">Information Technologies Support Services</asp:ListItem>
            <asp:ListItem Value="analyst">Systems Analyst</asp:ListItem>
        </asp:ListBox>

和这样的网格视图,

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            DataSourceID="XmlDataSource1">
            <Columns>
                <asp:BoundField DataField="name" HeaderText="Name" SortExpression="name" />
                <asp:BoundField DataField="program" HeaderText="Program" 
                    SortExpression="program" />
            </Columns>
        </asp:GridView>
        <asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/XMLFile.xml" 
            TransformFile="~/XSLTFile.xslt"></asp:XmlDataSource>

网格视图正在从 XML 和 XSLT 文件中获取值。我想要做的是,当用户从列表框中选择假设计算机程序员时,网格视图应该更新只有那些有这个程序的结果。我怎样才能做到这一点?我必须将 xml 与列表框绑定吗?

4

1 回答 1

1

您需要做的是DataSource根据GridViewListBox.

ListBox1's selected index 更改时,触发事件并使用AutoPostBack属性和 FilterXMLDataSource取决于选择的值是什么。

Protected Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
    Dim selected As String = ListBox1.SelectedValue
    FilterDataSource(selected)
End Sub

''' <summary>
''' Depending on the selected value passed in, filter the XMLDataSource
''' by the selected value
''' </summary>
''' <param name="selected">The value of the selected item in ListBox1</param>
''' <remarks></remarks>
Private Sub FilterDataSource(ByVal selected As String)
    ' Do whatever logic applies that will filter the XMLDataSource
    Select Case selected

        Case "all"

        Case "progammer"

        Case "itss"

        Case "analyst"

    End Select
End Sub
于 2012-06-18T02:20:32.593 回答