Datalist中怎么实现分页功能..!(急求在线等)
展开全部
GridView本身具有分页功能
Datalist需要自己写,给你一段代码,自己调试下
ASPX页加上这些东西:
<asp:label ID="lblCurrentPage" runat="server"></asp:label>
<asp:HyperLink id="LnkFirst" runat="server">首页</asp:HyperLink>
<asp:HyperLink id="lnkPrev" runat="server">上一页</asp:HyperLink>
<asp:HyperLink id="lnkNext" runat="server">下一页</asp:HyperLink>
<asp:HyperLink id="LnkLast" runat="server">尾页</asp:HyperLink>
CS页Page_Load里加上这些:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
PagedDataSource objPds = new PagedDataSource();
objPds.DataSource ={你的数据源};
objPds.AllowPaging = true;
objPds.PageSize = 10;
int CurPage;
//double temp = dt.Rows.Count / objPds.PageSize;
int PageCount = dtApp.Rows.Count / objPds.PageSize;
if (dtApp.Rows.Count % objPds.PageSize > 0)
{
PageCount++;
}
if (Request.QueryString["Page"] != null)
{
CurPage = Convert.ToInt32(Request.QueryString["Page"]);
}
else
{
CurPage = 1;
}
objPds.CurrentPageIndex = CurPage - 1;
lblCurrentPage.Text = "当前页:" + CurPage.ToString() + " 共" + PageCount.ToString() + "页";
LnkFirst.NavigateUrl = Request.CurrentExecutionFilePath ;
if (!objPds.IsFirstPage)
lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage - 1) ;
if (!objPds.IsLastPage)
lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage + 1) ;
LnkLast.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(PageCount) ;
Datalist1.DataSource = objPds;
Datalist1.DataBind();
}
}
Datalist需要自己写,给你一段代码,自己调试下
ASPX页加上这些东西:
<asp:label ID="lblCurrentPage" runat="server"></asp:label>
<asp:HyperLink id="LnkFirst" runat="server">首页</asp:HyperLink>
<asp:HyperLink id="lnkPrev" runat="server">上一页</asp:HyperLink>
<asp:HyperLink id="lnkNext" runat="server">下一页</asp:HyperLink>
<asp:HyperLink id="LnkLast" runat="server">尾页</asp:HyperLink>
CS页Page_Load里加上这些:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
PagedDataSource objPds = new PagedDataSource();
objPds.DataSource ={你的数据源};
objPds.AllowPaging = true;
objPds.PageSize = 10;
int CurPage;
//double temp = dt.Rows.Count / objPds.PageSize;
int PageCount = dtApp.Rows.Count / objPds.PageSize;
if (dtApp.Rows.Count % objPds.PageSize > 0)
{
PageCount++;
}
if (Request.QueryString["Page"] != null)
{
CurPage = Convert.ToInt32(Request.QueryString["Page"]);
}
else
{
CurPage = 1;
}
objPds.CurrentPageIndex = CurPage - 1;
lblCurrentPage.Text = "当前页:" + CurPage.ToString() + " 共" + PageCount.ToString() + "页";
LnkFirst.NavigateUrl = Request.CurrentExecutionFilePath ;
if (!objPds.IsFirstPage)
lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage - 1) ;
if (!objPds.IsLastPage)
lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage + 1) ;
LnkLast.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(PageCount) ;
Datalist1.DataSource = objPds;
Datalist1.DataBind();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询