首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从列表框更新网格视图

从列表框更新网格视图
EN

Stack Overflow用户
提问于 2012-06-18 09:45:45
回答 1查看 898关注 0票数 1

我有一个这样的列表框,

代码语言:javascript
复制
<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>

像这样的网格视图,

代码语言:javascript
复制
<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与列表框绑定?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-06-18 10:20:33

您需要做的是根据在ListBox中选择的内容过滤GridViewDataSource

ListBox1的选定索引发生更改时,使用AutoPostBack属性触发事件,并根据选定的值过滤XMLDataSource

代码语言:javascript
复制
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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11076156

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档