asp SqlDataSource 过滤表达式;多个搜索框

发布于 2024-11-16 18:27:32 字数 2110 浏览 2 评论 0原文

我正在尝试对 asp:GridView 中的单列数据执行单个搜索,但是我希望每列上方有多个筛选(搜索)框,以便可以在自己的透视列中进行搜索。理论上可以清楚地解决这个问题的是拥有多个FilterExpressions。我正在使用VB,而且很新,很容易对VB产生误解,请直接说:

PS。当只有一个过滤器(搜索)框时,我已经让它工作没有问题,这目前不执行任何操作

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    ConnectionString="xxx" 
    ProviderName="xxxx" 
    SelectCommand="SELECT [ddiID], [volusionID], [Customer], [email], [Total], [SumOfTotal] FROM [BBnewsalesQry] ORDER BY [Customer]"
    FilterExpression="customer like '%{0}%' OR ddiID like '%{0}%'">
      <FilterParameters>
         <asp:ControlParameter Name="ddiID" ControlID="ddiIDSearch" PropertyName="Text" />
         <asp:ControlParameter Name="customer" ControlID="txtSearch" PropertyName="Text" />
      </FilterParameters>
</asp:SqlDataSource>
<div>
   <b>DDI Search:</b> <asp:TextBox ID="ddiIDSearch" runat="server" />
   <b>Customer Search:</b> <asp:TextBox ID="txtSearch" runat="server" />
   <asp:ImageButton ID="btnSearch" ImageUrl="http:xxx" runat="server" />
   <asp:ImageButton ID="btnClear" ImageUrl="http:xxx" runat="server" />
</div>

然后在 GridView 内:

<asp:TemplateField HeaderText="ddiID" SortExpression="ddiID">
        <ItemStyle HorizontalAlign="Left" />
           <ItemTemplate>
              <asp:Label ID="lblddiid" Text='<%#HighlightText(Eval("ddiid")) %>' 
                        CssClass="TextField" runat="server" />
           </ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="volusionID" HeaderText="volusionID" ReadOnly="True" SortExpression="volusionID" />
<asp:TemplateField HeaderText="customer" SortExpression="customer">
         <ItemStyle HorizontalAlign="Left" />
           <ItemTemplate>
              <asp:Label ID="lblcustomer" Text='<%#HighlightText(Eval("customer")) %>' 
                        CssClass="TextField" runat="server" />
           </ItemTemplate>
</asp:TemplateField>

I am trying to perform a single search on a single column of data in an asp:GridView, however I want multiple filter (search) boxes above each column so one could search within its own perspective column. What would clearly fix this theoretically is to have multiple FilterExpressions. I am using VB and am very new and easily misunderstood with VB, please bare with:

PS. I have gotten it to work no problem when only having ONE filter (search) box, this currently doesn't do anything

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    ConnectionString="xxx" 
    ProviderName="xxxx" 
    SelectCommand="SELECT [ddiID], [volusionID], [Customer], [email], [Total], [SumOfTotal] FROM [BBnewsalesQry] ORDER BY [Customer]"
    FilterExpression="customer like '%{0}%' OR ddiID like '%{0}%'">
      <FilterParameters>
         <asp:ControlParameter Name="ddiID" ControlID="ddiIDSearch" PropertyName="Text" />
         <asp:ControlParameter Name="customer" ControlID="txtSearch" PropertyName="Text" />
      </FilterParameters>
</asp:SqlDataSource>
<div>
   <b>DDI Search:</b> <asp:TextBox ID="ddiIDSearch" runat="server" />
   <b>Customer Search:</b> <asp:TextBox ID="txtSearch" runat="server" />
   <asp:ImageButton ID="btnSearch" ImageUrl="http:xxx" runat="server" />
   <asp:ImageButton ID="btnClear" ImageUrl="http:xxx" runat="server" />
</div>

Then inside the GridView:

<asp:TemplateField HeaderText="ddiID" SortExpression="ddiID">
        <ItemStyle HorizontalAlign="Left" />
           <ItemTemplate>
              <asp:Label ID="lblddiid" Text='<%#HighlightText(Eval("ddiid")) %>' 
                        CssClass="TextField" runat="server" />
           </ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="volusionID" HeaderText="volusionID" ReadOnly="True" SortExpression="volusionID" />
<asp:TemplateField HeaderText="customer" SortExpression="customer">
         <ItemStyle HorizontalAlign="Left" />
           <ItemTemplate>
              <asp:Label ID="lblcustomer" Text='<%#HighlightText(Eval("customer")) %>' 
                        CssClass="TextField" runat="server" />
           </ItemTemplate>
</asp:TemplateField>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

贪恋 2024-11-23 18:27:32

您两次引用相同的参数 - 请尝试以下操作:

FilterExpression="customer like '%{0}%' OR ddiID like '%{1}%'"

you are referencing the same parameter twice - try the following:

FilterExpression="customer like '%{0}%' OR ddiID like '%{1}%'"
囍孤女 2024-11-23 18:27:32

我已经解决了在“Where”语句中创建两个或多个“Like 子句”的问题,使用:

Where CHARINDEX(@Par1, Col1)<>0) and ...

I have resolved the problem of create two or more "Like clause" in the "Where" statement using:

Where CHARINDEX(@Par1, Col1)<>0) and ...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文