本文介绍了筛选与sqldatasource绑定的GridView数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用sqldatasource filterexpression和参数过滤ASP中的gridview.我找不到我想念的东西.当我更改下拉菜单时,什么也没有发生.当我不熟悉ASP时,任何帮助将不胜感激.

这是下拉列表:

I''m trying to filter a gridview in asp with sqldatasource filterexpression and parameters. I can''t find what I''m missing. When I change the drop downs nothing happens. Any help would be greatly appreciated as I''m new to ASP.

Here is the dropdownlist:

<asp:DropDownList ID="dl_filter_Inst" runat="server" DataSourceID="ds_Inst"

                DataTextField="Num" DataValueField="Num" width="98%"

                AppendDataBoundItems="true">
                <asp:ListItem Selected="True" Value="">Show All</asp:ListItem>
                </asp:DropDownList>



这是数据源和filter参数:



Here is the datasource and filterparameters:

<asp:SqlDataSource ID="ds_Inst" runat="server"

    ConnectionString="<%$ ConnectionStrings:SAPConfiguration.My.MySettings.SqlConn %>"

    SelectCommand="getInst" InsertCommand="insertInst"

        InsertCommandType="StoredProcedure" SelectCommandType="StoredProcedure"

        UpdateCommand="updateInst" UpdateCommandType="StoredProcedure"

        OldValuesParameterFormatString="original_{0}" EnableCaching="True"

        CacheDuration="600" FilterExpression="Num like '{0}'">
        <FilterParameters>
            <asp:ControlParameter ControlID="dl_filter_Inst" Name="Num"

                PropertyName="SelectedValue" DefaultValue="&quot;&quot;" />
            <asp:ControlParameter ControlID="tb_filter_Name" Name="Name"

                PropertyName="Text" />
            <asp:ControlParameter ControlID="rb_Enabled" Name="Enabled"

                PropertyName="Checked" />
            <asp:ControlParameter ControlID="rb_branchBilling" Name="BranchBilling"

                PropertyName="Checked" />
            <asp:ControlParameter ControlID="dl_filter_DB" Name="DB"

                PropertyName="SelectedValue" />
            <asp:ControlParameter ControlID="dl_MF" Name="MF"

                PropertyName="SelectedValue" />
            <asp:ControlParameter ControlID="dl_center" Name="Center"

                PropertyName="SelectedValue" />
        </FilterParameters>




这是要过滤的gridview和列:




Here is the gridview and column to be filtered:

<asp:GridView ID="gv_Inst" runat="server" AutoGenerateColumns="False"

   DataSourceID="ds_Inst" AllowPaging="True" AllowSorting="True"

       AutoGenerateEditButton="True"

       PageSize="25" CssClass="gridview">
       <AlternatingRowStyle cssclass="altrow" />
   <Columns>
       <asp:BoundField DataField="Idx" HeaderText="Idx" SortExpression="Idx"

           InsertVisible="False" visible="false" >
       </asp:BoundField>
       <asp:BoundField DataField="Num" HeaderText="Number" SortExpression="Num"

           ReadOnly="False">
       <ControlStyle CssClass="controlClass" />
       </asp:BoundField>





[ ^ ] [ ^ ]





http://msdn.microsoft.com/en-us/library/ms227680(v=vs.100).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2[^]http://msdn.microsoft.com/en-us/library/ms227680(v=vs.100).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2[^]

推荐答案




Here is the gridview and column to be filtered:




Here is the gridview and column to be filtered:

<asp:GridView ID="gv_Inst" runat="server" AutoGenerateColumns="False"

   DataSourceID="ds_Inst" AllowPaging="True" AllowSorting="True"

       AutoGenerateEditButton="True"

       PageSize="25" CssClass="gridview">
       <AlternatingRowStyle cssclass="altrow" />
   <Columns>
       <asp:BoundField DataField="Idx" HeaderText="Idx" SortExpression="Idx"

           InsertVisible="False" visible="false" >
       </asp:BoundField>
       <asp:BoundField DataField="Num" HeaderText="Number" SortExpression="Num"

           ReadOnly="False">
       <ControlStyle CssClass="controlClass" />
       </asp:BoundField>





http://msdn.microsoft.com/en-us/library/ms227680(v=vs.100).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2[^]http://msdn.microsoft.com/en-us/library/ms227680(v=vs.100).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2[^]





http://msdn.microsoft.com/en-us/library/ms227680(v=vs.100).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2[^]http://msdn.microsoft.com/en-us/library/ms227680(v=vs.100).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2[^]


<asp:DropDownList ID="dl_filter_Inst" runat="server" DataSourceID="ds_Inst"

                AutoPostBack="True" 

                DataTextField="Num" DataValueField="Num" width="98%"

                AppendDataBoundItems="true">
                <asp:ListItem Selected="True" Value="">Show All</asp:ListItem>
                </asp:DropDownList>


Protected Sub btn_Apply_Click(sender As Object, e As EventArgs) Handles btn_Apply.Click
        gv_Inst.DataBind()
        btn_Clear.Enabled = True
    End Sub

    Protected Sub ds_Inst_Selecting(sender As Object, e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs) Handles ds_Inst.Selecting
        '<SelectParameters>
        '    <asp:Parameter Name="num" Type="String" />0
        '    <asp:Parameter Name="name" Type="String" />1
        '    <asp:Parameter Name="dbname" Type="String" />2
        '    <asp:Parameter Name="enable" Type="Boolean" />3
        '    <asp:Parameter Name="disable" Type="Boolean" />4
        '    <asp:Parameter Name="enableBranchBilling" Type="Boolean" />5
        '    <asp:Parameter Name="disableBranchBilling" Type="Boolean" />6
        '    <asp:Parameter Name="mainframe" Type="String" />7
        '    <asp:Parameter Name="center" Type="String" />8
        '  </SelectParameters>

        If cb_Inst.Checked Then
            e.Command.Parameters(0).Value = dl_filter_Inst.SelectedValue
        Else
            e.Command.Parameters(0).Value = "%"
        End If

        If cb_Name.Checked Then
            e.Command.Parameters(1).Value = tb_filter_Name.Text
        Else
            e.Command.Parameters(1).Value = "%"
        End If

        If cb_DB.Checked Then
            e.Command.Parameters(2).Value = dl_filter_DB.SelectedValue
        Else
            e.Command.Parameters(2).Value = "%"
        End If

        If cb_filter_Enable.Checked Then
            If rb_Enabled.Checked Then
                e.Command.Parameters(3).Value = True
                e.Command.Parameters(4).Value = True
            Else
                e.Command.Parameters(3).Value = False
                e.Command.Parameters(4).Value = False
            End If
        Else
            e.Command.Parameters(3).Value = True
            e.Command.Parameters(4).Value = False
        End If

        If cb_filter_BranchBilling.Checked Then
            If rb_branchBilling.Checked Then
                e.Command.Parameters(5).Value = True
                e.Command.Parameters(6).Value = True
            Else
                e.Command.Parameters(5).Value = False
                e.Command.Parameters(6).Value = False
            End If
        Else
            e.Command.Parameters(5).Value = True
            e.Command.Parameters(6).Value = False
        End If

        If cb_MF.Checked Then
            e.Command.Parameters(7).Value = dl_MF.SelectedValue
        Else
            e.Command.Parameters(7).Value = "%"
        End If

        If cb_Center.Checked Then
            e.Command.Parameters(8).Value = dl_center.SelectedValue
        Else
            e.Command.Parameters(8).Value = "%"
        End If
    End Sub


这篇关于筛选与sqldatasource绑定的GridView数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 00:28