我有一个这样的列表框,
<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&amp; XSLT文件。我想要做的是,当用户从列表框中选择“假设计算机程序员”时,网格视图应该仅使用具有此程序的结果进行更新。我怎样才能做到这一点?我是否必须将xml与列表框绑定?
答案 0 :(得分:1)
您需要做的是根据DataSource
中选择的内容过滤GridView
ListBox
。
当ListBox1
选定的索引发生变化时,请使用AutoPostBack
属性触发事件并根据所选值的内容过滤XMLDataSource
。
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