在GridView控件自定义分页 [英] custom paging on gridview control
问题描述
低于code,如果我删除 PagerSetting 或删除 PagerTemplate 所以,如果我有两个( PagerSetting &放大器工作正常> PagerTemplate ),那么我的页码不会显示。
below code works fine if i remove the PagerSetting or remove PagerTemplate so if i have both (PagerSetting & PagerTemplate) then my page number is not display.
我qeustion是:我怎么可以显示的(PagerTemplate和PagerSetting )togather在GridView的底部?普莱舍看到下面的源$ C $ C。
my qeustion is: how can i display both (PagerTemplate and PagerSetting) togather at the bottom of the Gridview ? plese see the below source code.
<asp:GridView ID="gvTable" runat="server" ShowHeader="true"
PageSize="5" AllowPaging="true" AllowSorting="true"
DataSourceID="myLinqDataSource" AutoGenerateColumns="false"
OnRowDataBound="GridView_DataBound">
<Columns>
<asp:BoundField DataField="Edited" HeaderText="Date" DataFormatString="{0:d}" />
<asp:BoundField DataField="Activity" HeaderText="Notes" />
</Columns>
<PagerStyle CssClass="pager-row" />
<RowStyle CssClass="row" />
<PagerSettings Mode="NumericFirstLast" PageButtonCount="7" FirstPageText="«" LastPageText="»" />
**<PagerTemplate>**
<div style="float: left; margin-left: 12px;">
<div style="float: left; margin: 4px 6px 0px 0px;">Page Size</div>
<asp:DropDownList ID="ddlPageSizeChange" runat="server" AutoPostBack="true" OnSelectedIndexChanged="PageSizeChange">
<asp:ListItem>15</asp:ListItem>
<asp:ListItem>25</asp:ListItem>
<asp:ListItem>50</asp:ListItem>
<asp:ListItem>100</asp:ListItem>
</asp:DropDownList>
</div>
<div class="gridCount" runat="server" id="divGridCount"><b>1</b> Items Found </div>
</PagerTemplate>
</asp:GridView>
更新1:
我能够显示分页1 2 3 4 5 ...但问题是:我不能兼得PagerSetting&放大器; PagerTemplate如果我有两个(PagerSetting&安培; PagerTemplate)在我的GridView我传呼(1 2 3 4 5)不显示,如果我删除PagerTemplate比我的分页显示(1 2 3 4 5 ...)有意义吗?
I able to display paging 1 2 3 4 5... but the problem is: i can not have both PagerSetting & PagerTemplate and if i have both(PagerSetting & PagerTemplate) in my gridview my paging (1 2 3 4 5) is not displaying and if i remove PagerTemplate than my paging is displaying (1 2 3 4 5...) make sense?
更新:
下面是我想获得:
&LT;&LT; &LT; 1 2 3 4 5 ...> >> 总页数发现有80 的 - 1/80页 - 每页{15,25,50,10 }(这将是一个DropDownList)
<< < 1 2 3 4 5 ..... > >> Total Pages Found 80 - Page 1/80 - PageSize {15,25,50,10} (this will be a dropdownlist)
推荐答案
您可以通过如下code做到这一点。
you can do this by using follow code
-
后端code(GridView中的行创建的事件):
Back end code ( row created event of gridview):
protected void GridView_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Pager)
{
TableRow tr = (TableRow)e.Row.Cells[0].Controls[0].Controls[0];
if (tr.Cells[1] != null && (((tr.Cells[1]).Controls[0]) is LinkButton))
{
LinkButton btnPrev = (LinkButton)(tr.Cells[1]).Controls[0];
if (btnPrev.Text == "...")
{
(((tr.Cells[1]).Controls[0]) as LinkButton).Text = "<";
}
}
if (tr.Cells[tr.Cells.Count - 2] != null && (((tr.Cells[tr.Cells.Count - 2]).Controls[0]) is LinkButton))
{
LinkButton btnNext = (LinkButton)(tr.Cells[tr.Cells.Count - 2]).Controls[0];
if (btnNext.Text == "...")
{
(((tr.Cells[tr.Cells.Count - 2]).Controls[0]) as LinkButton).Text = ">";
}
}
}
}
和使用pagersetting为:
and use pagersetting as:
<PagerSettings Mode="NumericFirstLast" FirstPageText="<<"
LastPageText=">>" />
你会得到你的输出。 :)
you will get your output. :)
请注意:不要忘了将的的pageSize 的和 AllowPaging =真正的的格
Note: don't forgot to set pageSize and AllowPaging ="true" of grid.
这篇关于在GridView控件自定义分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!