Click here to Skip to main content
15,172,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I apply FilterExpression values but when I want to change page the filter is cleared.
What can I do to avoid this?

I set filter this way:
SqlDataSource1.FilterExpression = "type= 10";  

The GridView is in
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">

Thank you.

[edit]Code block added, "Ignore HTML..." option disabled - OriginalGriff[/edit]
Updated 13-Jul-11 5:25am

1 solution

I do this Workaround and works:

on click event after:
   SqlDataSource1.FilterExpression = "some expression";
   ViewState.Add("filter", SqlDataSource1.FilterExpression);
Page_Load {
    if (Page.IsPostBack) {
        if (ViewState["filter"] != null) {
            SqlDataSource1.FilterExpression = ViewState["filter"].ToString();

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