请教各位大虾. . .
如何实现在GridView分页中实现如下样式,
例:
首页 上一页 1 2 3 4 5 6 下一页 末页
中间的页码的数量可以定义和修改,格式如上!
有大虾会的速回啊!
急救 急救~
如何实现在GridView分页中实现如下样式,
例:
首页 上一页 1 2 3 4 5 6 下一页 末页
中间的页码的数量可以定义和修改,格式如上!
有大虾会的速回啊!
急救 急救~
(1) 是否允许分页
GridView的AllowPaging属性。 (2) 每页记录数
GridView的PageSize (3) 分页导航条形式
GridView的PagerSettings属性的Mode:Numeric,NextPrevious,NextPreviousFirstLast,NumericFirstLast。 2. 自定义分页
(1) 当前页 <asp:Label ID="LabelCurrentPage" runat="server"
Text="<%# ((GridView)Container.NamingContainer).PageIndex + 1 %>"></asp:Label> (2) 总页数
<asp:Label ID="LabelPageCount" runat="server"
Text="<%# ((GridView)Container.NamingContainer).PageCount %>"></asp:Label> (3) 首页、上一页、下一页、尾页
<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:GridView ID="GridView2" runat="server" AllowSorting="True" AutoGenerateColumns="False"
Height="138px" PageSize="2" Width="187px">
<PagerSettings PageButtonCount="4" Mode="NumericFirstLast" />
<Columns>
<asp:BoundField DataField="TestStr" FooterText="Test" HeaderText="Test" />
</Columns>
<PagerTemplate>
<asp:Label ID="LabelCurrentPage" runat="server"
Text="<%# ((GridView)Container.NamingContainer).PageIndex + 1 %>"></asp:Label> (2) 总页数
<asp:Label ID="LabelPageCount" runat="server"
Text="<%# ((GridView)Container.NamingContainer).PageCount %>"></asp:Label> (3) 首页、上一页、下一页、尾页
<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>
</PagerTemplate>
</asp:GridView>
public void DataList()
{
SqlConnection conn = new SqlConnection(ConnectionString);
conn.Open(); SqlDataAdapter da = new SqlDataAdapter("select * from Ware", conn);
DataSet ds = new DataSet(); da.Fill(ds, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "Ware"); AspNetPager1.AlwaysShow = true;
AspNetPager1.PageSize = 3; DataList1.DataSource = ds;
DataList1.DataBind();
} protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BinDataList4();
SqlConnection conn = new SqlConnection(ConnectionString);
conn.Open(); SqlCommand cmd = new SqlCommand("select count(*) from Ware", conn);
cmd.Connection = conn;
AspNetPager1.RecordCount = (int)cmd.ExecuteScalar();
conn.Close(); datalistBind();
DataList();
}
}
而这个下一行 ,上一行 就简单了 直接在你的pageindexchange里面写就是了,
前提是容许分页.
希望楼主成功.
(3) 分页导航条形式
GridView的PagerSettings属性的Mode:Numeric,NextPrevious,NextPreviousFirstLast,NumericFirstLast。
(中间定义 页码数量)
首页 上一页 << 2 3 4 5 6 7 >> 下一页 末页
(<< 上几个) (>> 下几个)
老板不满意NumericFirstLast分页样式,要指定这样分页样式. . .
另外因为我是刚接手别人已经大部分完成的项目,他们用的是ArrayList[]数组取的实体对象,
不是用的DataSet,并且底层已经写好了!
我不好改动. . . 也不好使用AspnetPager 和 DataSource 控件做分页!
现在我都极度郁闷了>..