一个自动分页的 DataGridView1 已经有数据了求 DataGridView1 的总记录数,每页的分页行数,当前所在的页
一个自动分页的 DataGridView1 已经有数据了,比如自动 分了 X页
求 DataGridView1 的总记录数,每页的分页行数,当前所在的页
要 用DataGridView1 的属性取,而不再用SQL语句向数据库中取
------解决方案----------------------gridview的属性
<PagerTemplate>
<table style="width:100%" border="1">
<tr>
<td>
<asp:LinkButton ID="LinkButtonFirstPage" runat="server" CommandArgument="First" CommandName="Page"
Visible="<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>">首页</asp:LinkButton>
<asp:LinkButton ID="LinkButtonPreviousPage" runat="server" CommandArgument="Prev" CommandName="Page"
Visible="<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>">上一页</asp:LinkButton>
<asp:LinkButton ID="LinkButtonNextPage" runat="server" CommandArgument="Next" CommandName="Page"
Visible="<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>">下一页</asp:LinkButton>
<asp:LinkButton ID="LinkButtonLastPage" runat="server" CommandArgument="Last" CommandName="Page"
Visible="<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>">尾页</asp:LinkButton>
<asp:Label ID="LabelLabelCurrentPage1" runat="server" ForeColor ="RoyalBlue">第</asp:Label>
<asp:Label ID="LabelCurrentPage" runat="server" ForeColor ="RoyalBlue"
Text="<%# ((GridView)Container.NamingContainer).PageIndex + 1 %>"></asp:Label>
<asp:Label ID="LabelPageCount1" runat="server" ForeColor ="RoyalBlue" >/</asp:Label>
<asp:Label ID="LabelPageCount" runat="server" ForeColor ="RoyalBlue"
Text="<%# ((GridView)Container.NamingContainer).PageCount %>"></asp:Label>
<asp:Label ID="Label2" runat="server" ForeColor ="RoyalBlue" >页</asp:Label>
</td>
</tr>
</table>
</PagerTemplate>
------解决方案-------------------- /// <summary>
/// 在 GridView 控件中的某个行被绑定到一个数据记录时发生。此事件通常用于在某个行被绑定到数据时修改该行的内容。
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
this.lblCurrentPage.Text = string.Format("当前第{0}页/总共{1}页", this.GridView1.PageIndex + 1, this.GridView1.PageCount);
//遍历所有行设置边框样式
foreach (TableCell tc in e.Row.Cells)
{
tc.Attributes["style"] = "border-color:Black";