使用objectdatasource在gridview中排序,起始行索引恢复为0 [英] sorting in gridview using objectdatasource, start row index reverts to 0
本文介绍了使用objectdatasource在gridview中排序,起始行索引恢复为0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
有谁能够帮助我.我有一个使用对象数据源的网格视图.我有分页.让我说我在第3页上.每当我点击排序列链接之一时,起始行索引就会恢复为0.这将我指向第1页,而不是第3页.有人可以帮助我吗?
< asp:GridView ID =" ="span> runat =" 服务器" AutoGenerateColumns 错误" AllowPaging =" DataSourceID ="
EnableSortingAndPagingCallbacks =" True" ShowFooter 真实" AllowSorting ="
OnRowCommand =" gvCategory_RowCommand" 宽度 100%" OnRowDataBound =" >
< 列 >
< asp:TemplateField HeaderText =" HeaderStyle-Width 2%" HeaderStyle-HorizontalAlign 左"
HeaderStyle-字体下划线 =" >
< ItemTemplate >
<%#((((GridView)((GridViewRow)Container).Parent.Parent).PageIndex)*((GridView)((GridViewRow)Container).Parent .Parent).PageSize+ Container.DataItemIndex + 1 %>
< asp:HiddenField ID =" runat 服务器" 值 <%#Eval(" )%> ' / >
< /ItemTemplate >
< HeaderStyle =" 错误" HorizontalAlign 左" 宽度 2%" / >
< /asp:TemplateField >
< asp:BoundField 数据字段 =" HeaderText 类别名称" SortExpression 类别名称" / >
< asp:BoundField 数据字段 =" HeaderText 类别说明"
SortExpression 类别描述" / >
< asp:BoundField DataField =" HeaderText 状态" SortExpression StatusDesc" / < asp:TemplateField HeaderStyle-字体-下划线 =" HeaderStyle-Width =" ShowHeader =" >
< ItemTemplate >
< asp:LinkButton ID =" runat 服务器" CausesValidation 错误" CommandArgument " )%> '
CommandName =" / >
< /ItemTemplate >
< HeaderStyle =" 错误" 宽度 5 %" / < /asp:TemplateField >
< /列 >
< EmptyDataTemplate >
< asp:Label ID =" runat 服务器" SkinID GridViewNoDataAvailable"
文本 未找到记录" < >
< /EmptyDataTemplate >
< /asp:GridView >
< asp:ObjectDataSource ID =" TypeName IFBS .Web.Course.Maint.UI.GridViewListingClass" SelectMethod BindGrid" 短跑 ="
span> SelectCountMethod =" GetGridRowCount" EnablePaging true" StartRowIndexParameterName =" MaximumRowsParameterName =" SortParameterName =" >
< SelectParameters >
< asp:ControlParameter 名称 =" =" txtSearch" PropertyName =" >
< asp:ControlParameter 名称 =" =" gvCategory" PropertyName =" >
< /SelectParameters >
在此先感谢
prasharvi
解决方案
在对数据进行排序之前,为什么不存储页码,而在排序之后又返回该页码.
虽然,这完全是个人决定(或由需求决定),但我还是希望在排序后重新设置页码,因为整个数据可能会发生变化,而且如果我仍旧使用某些旧页码,我将一无所知.
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.
<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
解决方案
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.
这篇关于使用objectdatasource在gridview中排序,起始行索引恢复为0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文