我有一个这样的列表框,
<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与列表框绑定?
发布于 2012-06-18 10:20:33
您需要做的是根据在ListBox中选择的内容过滤GridView的DataSource。
当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 Subhttps://stackoverflow.com/questions/11076156
复制相似问题