[英]custom paging on gridview control
下面的代码工作正常,如果我删除PagerSetting或删除PagerTemplate所以如果我同时( PagerSetting和PagerTemplate )然后我的页码不显示。
我的qeustion是:我如何在Gridview的底部显示(PagerTemplate和PagerSetting )? 请参阅以下源代码。
<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,如果我在gridview中同时拥有(PagerSetting和PagerTemplate)我的分页(1 2 3 4 5)不是显示,如果我删除PagerTemplate比我的分页显示(1 2 3 4 5 ...)有意义吗?
更新:
这是我想要得到的:
<< <1 2 3 4 5 .....> >> 找到的总页数80 - 第1/80页 - PageSize {15,25,50,10}(这将是一个下拉列表)
你可以使用以下代码来做到这一点
后端代码(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:
<PagerSettings Mode="NumericFirstLast" FirstPageText="<<" LastPageText=">>" />
你会得到你的输出。 :)
注意:不要忘记设置网格的pageSize和AllowPaging =“true” 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.