开发者

asp SqlDataSource Filter Expression; multiple Search Boxes

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="x开发者_如何学Goxx" 
    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>


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

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


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

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜