Mesh filter

I have a gridview that I bind with the code behind, I want to filter the gridview based on the value set by the user in the text box.

It would be great if I can filter the gridview without postback.

PLease support!

Thanks in advance

+3
source share
3 answers

you can run filter expression

<asp:sqldatasource id="articles" runat="server"
   connectionstring="<%$ ConnectionStrings:aspa %>" 
   selectcommand="SELECT title, url, added, updated FROM aspx_articles ORDER BY title" 
   filterexpression="title LIKE '%{0}%' or url LIKE '%{0}%'">
   <filterparameters>
      <asp:controlparameter controlid="searchBox" propertyname="Text" />
   </filterparameters>
</asp:sqldatasource>

or in this way

Do you have a TextBox outside of the GridView, and when you enter data into it and click the button, should GirdView filter this data?

, , select taka , . ControlParameter SelectParameters DataSource ( DataSource).

, Northwind, , :

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Button" />
        <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
            DataKeyNames="ProductID" DataSourceID="SqlDataSource1" ShowFooter="True">
            <Columns>
                <asp:CommandField ShowSelectButton="True" />
                <asp:BoundField DataField="ProductID" HeaderText="ProductID" InsertVisible="False"
                    ReadOnly="True" SortExpression="ProductID" />
                <asp:BoundField DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName" />
                <asp:BoundField DataField="UnitsInStock" HeaderText="UnitsInStock" SortExpression="UnitsInStock" />
                <asp:BoundField DataField="UnitPrice" HeaderText="UnitPrice" SortExpression="UnitPrice" />
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
            SelectCommand="SELECT [ProductID], [ProductName], [UnitsInStock], [UnitPrice] FROM [Alphabetical list of products] WHERE ([ProductName] LIKE '%' + @ProductName + '%')">
            <SelectParameters>
                <asp:ControlParameter ControlID="TextBox1" DefaultValue="%" Name="ProductName" PropertyName="Text"
                    Type="String" />
            </SelectParameters>
        </asp:SqlDataSource>

, http://forums.asp.net/p/1034014/2904713.aspx

+5

, - (, Microsoft Ajax Library dataView). gridview . , - this .

+2

. , JavaScript, , . , AJAX, . .

EDIT :

<asp:ScriptManager ID="ScriptManager1" AllowCustomErrorsRedirect="false"  runat="server"></asp:ScriptManager>

  <asp:UpdatePanel ID="UpdatePanel1"  runat="server">
    <ContentTemplate>

            <asp:TextBox runat="server" ID="txtFilterString" ></asp:TextBox>
            <asp:Button runat="server" ID="btnFilter" Text="FilterResults" onclick="btnFilter_Click" /> 

            <asp:GridView runat="server" ID="grdResults"
                DataKeyNames="Id"
                AllowSorting="true" AllowPaging="true" PageSize="20" 
                PagerSettings-Mode="NumericFirstLast">
                    <Columns>
                        .....
                    </Columns>          
                </asp:GridView>


  </asp:UpdatePanel>
+1

Source: https://habr.com/ru/post/1743396/


All Articles