Hi Everyone,
I have been making myself crazy over this one and can't find anything on the web about it. I have a gridview that uses paging. The Gridview is bound to SqlDataSource. I use filter expressions so my users can filter the records. The Gridview pages at every 10 records. If the filtered DataSource returns more than 10 records and the user clicks to move to another page, the filter is lost and the Gridview reverts back to showing all records. Here is my markup:
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" BackColor="White" BorderColor="#336666" BorderStyle="Double" BorderWidth="3px" CellPadding="4" DataSourceID="SqlDataSource1" GridLines="Horizontal" Width="100%" DataKeyNames="WONumber"><Columns><asp:CommandField ShowSelectButton="True" /><asp:TemplateField HeaderText="PR" SortExpression="Priority"><ItemTemplate><asp:Image runat="server" ID="PriorityImage" ImageUrl="~/Images/PriorityLow.jpg" /></ItemTemplate></asp:TemplateField><asp:BoundField DataField="WONumber" HeaderText="Order #" InsertVisible="False" ReadOnly="True" SortExpression="ID" /><asp:BoundField DataField="Date" HeaderText="Date" SortExpression="Date" dataformatstring="{0:MMMM d, yyyy}" /><asp:BoundField DataField="Type" HeaderText="Type" SortExpression="Type" /><asp:BoundField DataField="Property" HeaderText="Property" SortExpression="Property" /><asp:BoundField DataField="Requested By" HeaderText="Requested By" SortExpression="Requested By" /><asp:BoundField DataField="Repair Item" HeaderText="Repair Item" SortExpression="Repair Item" /><asp:BoundField DataField="FullName" HeaderText="Tech" SortExpression="FullName" /><asp:BoundField DataField="Order Status" HeaderText="Status" SortExpression="Order Status" /><asp:BoundField DataField="ServiceType" HeaderText="Svc Type" SortExpression="ServiceType" /><asp:BoundField DataField="Priority" HeaderText ="" ItemStyle-ForeColor="silver" ItemStyle-BackColor="Silver" ><ItemStyle BackColor="Silver" ForeColor="Silver"></ItemStyle></asp:BoundField></Columns><FooterStyle BackColor="White" ForeColor="#333333" /><HeaderStyle BackColor="#336666" Font-Bold="True" ForeColor="White" /><PagerSettings NextPageImageUrl="~/Images/NextButton.png" Position="Bottom" PreviousPageImageUrl="~/Images/PrevButton.png" /><PagerStyle BackColor="#336666" ForeColor="White" HorizontalAlign="Center" /><pagerStyle CssClass="gvPagerCss" /><RowStyle BackColor="White" ForeColor="#333333" /><SelectedRowStyle BackColor="#339966" Font-Bold="True" ForeColor="White" /><SortedAscendingCellStyle BackColor="#F7F7F7" /><SortedAscendingHeaderStyle BackColor="#487575" /><SortedDescendingCellStyle BackColor="#E5E5E5" /><SortedDescendingHeaderStyle BackColor="#275353" /></asp:GridView><ajaxToolkit:RoundedCornersExtender ID="GridView1_RoundedCornersExtender" runat="server" BehaviorID="GridView1_RoundedCornersExtender" TargetControlID="GridView1" /><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:WODBConnection %>" SelectCommand="SELECT tblWorkOrders.ID, tblWorkOrders.WONumber, tblWorkOrders.ServiceRequestDate AS Date, tblWorkOrders.OrderType AS Type, tblProperties.Property, tblWorkOrders.ServiceRequestedBy AS [Requested By], tblRepairItems.Description AS [Repair Item], tblUsers.FullName, tblWorkOrders.Status AS [Order Status], tblWorkOrders.ServiceType, tblWorkOrders.Priority FROM tblWorkOrders LEFT OUTER JOIN tblUsers ON tblWorkOrders.ServiceTechID = tblUsers.id LEFT OUTER JOIN tblRepairItems ON tblWorkOrders.RepairCode = tblRepairItems.id LEFT OUTER JOIN tblProperties ON tblWorkOrders.PropertyID = tblProperties.ID ORDER BY Date DESC"></asp:SqlDataSource>
Here is my code behind:
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load If Not IsPostBack Then Dim FilterExpression As String Select Case Session("Type") Case "1" FilterExpression = "1" Case "2" FilterExpression = "2" Case Else FilterExpression = "" End Select End If End Sub Protected Sub btnAll_Click(sender As Object, e As EventArgs) Handles btnAll.Click Dim FilterExpression As String = "" 'Me.GridView1.DataBind() End Sub Protected Sub btnOpenOrders_Click(sender As Object, e As EventArgs) Handles btnOpenOrders.Click Dim FilterExpression As String = "[Order Status]='Open'" Me.SqlDataSource1.FilterExpression = FilterExpression 'Me.GridView1.DataBind() End Sub Protected Sub btnInProgress_Click(sender As Object, e As EventArgs) Handles btnInProgress.Click Dim FilterExpression As String = "[Order Status]='In Progress'" Me.SqlDataSource1.FilterExpression = FilterExpression 'Me.GridView1.DataBind() End Sub Protected Sub btnClosedOrders_Click(sender As Object, e As EventArgs) Handles btnClosedOrders.Click Dim FilterExpression As String = "[Order Status]='Closed'" Me.SqlDataSource1.FilterExpression = FilterExpression 'Me.GridView1.DataBind() End Sub Protected Sub btnSearch_Click(sender As Object, e As ImageClickEventArgs) Handles btnSearch.Click Dim FilterExpression As String = "[Property] Like '" & Me.txtSearch.Text & "%'" Me.SqlDataSource1.FilterExpression = FilterExpression 'Me.GridView1.DataBind() End Sub
As you can see, I commented out all of the databinds, the result is the same either way. Anyone see what I am missing here?