Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
Can anybody help me. I have a grid view which uses object data source. I have pagination. Let me say that I am on page 3. The start row index reverts to 0 every time I hit one of the sort column links. This points me to page 1 instead of remaining on page 3. Could someone help me.


XML
<asp:GridView ID="gvCategory" runat="server" AutoGenerateColumns="False" AllowPaging="True" DataSourceID="objDs"
                            EnableSortingAndPagingCallbacks="True" ShowFooter="True" AllowSorting="True"
                            OnRowCommand="gvCategory_RowCommand" Width="100%" OnRowDataBound="gvCategory_RowDataBound" >
                            <Columns>
                                <asp:TemplateField HeaderText="#" HeaderStyle-Width="2%" HeaderStyle-HorizontalAlign="Left"
                                    HeaderStyle-Font-Underline="false">
                                    <ItemTemplate>
                                        <%# (((GridView)((GridViewRow)Container).Parent.Parent).PageIndex) * ((GridView)((GridViewRow)Container).Parent.Parent).PageSize + Container.DataItemIndex + 1 %>
                                        <asp:HiddenField ID="hdfID" runat="server" Value='<%# Eval("ID") %>' />
                                    </ItemTemplate>
                                    <HeaderStyle Font-Underline="False" HorizontalAlign="Left" Width="2%" />
                                </asp:TemplateField>
                                <asp:BoundField DataField="CategoryName" HeaderText="Category Name" SortExpression="CategoryName" />
                                <asp:BoundField DataField="CategoryDescription" HeaderText="Category Description"
                                    SortExpression="CategoryDescription" />
                                <asp:BoundField DataField="StatusDesc" HeaderText="Status" SortExpression="StatusDesc" />
                                <asp:TemplateField HeaderStyle-Font-Underline="false" HeaderStyle-Width="5%" ShowHeader="False">
                                    <ItemTemplate>
                                        <asp:LinkButton ID="lnkGvSelect" runat="server" CausesValidation="False" CommandArgument='<%# Eval("ID") %>'
                                            CommandName="Select"  />
                                    </ItemTemplate>
                                    <HeaderStyle Font-Underline="False" Width="5%" />
                                </asp:TemplateField>
                            </Columns>
                            <EmptyDataTemplate>
                                <asp:Label ID="lblNoAvailableData" runat="server" SkinID="GridViewNoDataAvailable"
                                    Text="No Record Found"></asp:Label>
                            </EmptyDataTemplate>
                        </asp:GridView>



<asp:ObjectDataSource ID="objDs" TypeName="IFBS.Web.Course.Maint.UI.GridViewListingClass" SelectMethod="BindGrid" runat="server" 
        SelectCountMethod="GetGridRowCount" EnablePaging="true" StartRowIndexParameterName="StartRow" MaximumRowsParameterName="PageSize" SortParameterName="SortBy" >
        <SelectParameters>
            <asp:ControlParameter Name="srchTxt"  ControlID="txtSearch" PropertyName="Text" />
            <asp:ControlParameter Name="pgIdx"  ControlID="gvCategory" PropertyName="PageIndex" />
            
        </SelectParameters>


Thanks in advance
prasharvi
Posted

1 solution

Before sorting the data, why not store the page number and after sorting go back to that page number.

Though, it's completely personal decision(or driven by requirements), I would prefer a page number reset too after sorting as whole data might change and I would have no clue if I am still on some old page number.
 
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