Click here to Skip to main content
15,916,019 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi everyone,

i have a problem, i made a gridview and i am filtering the grideview content on the bases of selected content by the user from dropdownlist... i am also using paging in the gridview, it shows 10 rows at a time...now when i select the content from the dropdownlist the grideview content filters and if the filter content is more than 10 rows paging occurs...and when i click on the next page the gridview shows the content of next page but not the content of filtered grideview next page??

please help me how can i do paging on filtered content of the gridview???
Posted

Hi,
I do not know what datasource you use to fill your GridView. However, despite the type of the datasource(ObjectDataSource, SqlDataSource, or ...) you need to set filter parameter for these sources to filter them on very postback.

I hope it helps,
Cheers.
 
Share this answer
 
Comments
badbooy8192 7-Apr-12 8:56am    
@Reza Ahmadi thanx 4 taking interest in my question...
i am using SqlDataSource...i am able to filter the content...
but my problem is that after filtering if there are more than 10 records paging occurs and when i click on next page, the gridview is not able to show the next page of filtered record...dats my problem...please help me out...

i can also upload a small appliction for it if u need it...:)
Reza Ahmadi 7-Apr-12 10:44am    
Hi,
Take a look at this page which exactly address your question:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.filterexpression.aspx
Hi ,
Try this example will give Idea ,Hope it help you
C#
protected void Page_Load(object sender, EventArgs e)
{

}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    if (ViewState["flag"] !=null)
    {
        if ((bool)ViewState["flag"] == true)
        {
            SqlDataSource1.FilterExpression = "Item_name like '%trr4%'";
        }
    }
}
protected void Button1_Click(object sender, EventArgs e)
{
    ViewState.Add("flag", true);

    SqlDataSource1.FilterExpression = "Item_name like '%trr4%'";
    GridView1.DataSourceID = "";
    GridView1.DataSourceID = "SqlDataSource1";
    //GridView1.DataSource = SqlDataSource1;
    GridView1.DataBind();
}


XML
<div>
    <asp:GridView ID="GridView1" runat="server" AllowPaging="True"
        AutoGenerateColumns="False" DataKeyNames="item_code"
        DataSourceID="SqlDataSource1" onpageindexchanging="GridView1_PageIndexChanging"
        PageSize="3">
        <Columns>
            <asp:BoundField DataField="item_code" HeaderText="item_code"
                InsertVisible="False" ReadOnly="True" SortExpression="item_code" />
            <asp:BoundField DataField="Item_name" HeaderText="Item_name"
                SortExpression="Item_name" />
            <asp:BoundField DataField="brand" HeaderText="brand" SortExpression="brand" />
            <asp:BoundField DataField="size" HeaderText="size" SortExpression="size" />
            <asp:BoundField DataField="section" HeaderText="section"
                SortExpression="section" />
            <asp:BoundField DataField="price" HeaderText="price" SortExpression="price" />
            <asp:BoundField DataField="Material" HeaderText="Material"
                SortExpression="Material" />
            <asp:BoundField DataField="Qty" HeaderText="Qty" SortExpression="Qty" />
            <asp:BoundField DataField="tax" HeaderText="tax" SortExpression="tax" />
            <asp:BoundField DataField="tt" HeaderText="tt" SortExpression="tt" />
        </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
        ConnectionString="<%$ ConnectionStrings:testConnectionString %>"
        SelectCommand="SELECT * FROM [Items]"></asp:SqlDataSource>
    <br />
    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</div>



Best Regards
M.Mitwalli
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900