asp.net求一个分页的代码
用datalist绑定的数据源。代码不要太复杂本人新手。有首页、上页、下页、尾页功能及可。代码要有注释适合新手的内容!废话,我要用dataview还要你说,你以为全世界就...
用datalist绑定的数据源。代码不要太复杂本人新手。有首页、上页、下页、尾页功能及可。代码要有注释适合新手的内容!
废话,我要用dataview还要你说,你以为全世界就你一个聪明人么。 展开
废话,我要用dataview还要你说,你以为全世界就你一个聪明人么。 展开
4个回答
展开全部
DataList分页的话需要后台代码
用GridView自带分页
用GridView自带分页
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
翻页的话,有几种方法,最简单的是用自带的翻页功能,在就是还可以你自己写一些翻页方法,在页面调用给datalist,我用的是一个叫aspnetpager的翻页控件,你可以在网上搜搜,用法跟其他控件一样,直接拖到页面上就行了,然后就是后台代码绑定,给你一个我以前绑定的方法看看:
private void DataBinds()
{
PagedDataSource pds = new PagedDataSource();
pds.DataSource = BookManager.GetNewBooks();//写你自己的方法
pds.AllowPaging = true;
pds.CurrentPageIndex = this.AspNetPager1.CurrentPageIndex - 1;
this.AspNetPager1.RecordCount = 20;//数据总数,我这里直接写20,应该是你数据count()值
pds.PageSize = this.AspNetPager1.PageSize;
this.datalist.DataSource = pds;
this.datalist.DataBind();
}
private void DataBinds()
{
PagedDataSource pds = new PagedDataSource();
pds.DataSource = BookManager.GetNewBooks();//写你自己的方法
pds.AllowPaging = true;
pds.CurrentPageIndex = this.AspNetPager1.CurrentPageIndex - 1;
this.AspNetPager1.RecordCount = 20;//数据总数,我这里直接写20,应该是你数据count()值
pds.PageSize = this.AspNetPager1.PageSize;
this.datalist.DataSource = pds;
this.datalist.DataBind();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public void databinds(string id,string bigcode,string smallcode,string count)
{
bool pageshow=true;
DataSet ds_news=Q.Qry_type_news("",bigcode,smallcode,"");
if (ds_news.Tables[0].Rows.Count>0)
{
PagedDataSource objPage = new PagedDataSource();
//设置数据源
objPage.DataSource = ds_news.Tables[0].DefaultView;
//允许分页
objPage.AllowPaging = true;
//设置每页显示的项数
objPage.PageSize = 14;
//定义变量用来保存当前页索引
int CurPage=1;
//判断是否具有页面跳转的请求
if(!pageshow)
CurPage = 1;
else if (Request.QueryString["Page"] != null)
CurPage=Convert.ToInt32(Request.QueryString["Page"]);
//设置当前页的索引
int countnumber = ds_news.Tables[0].Rows.Count;
double db = countnumber/objPage.PageSize;
int n = int.Parse(db.ToString());
if(countnumber!=objPage.PageSize*n)
{
n+=1;
}
if (n==0) n = 1;
objPage.CurrentPageIndex = CurPage-1;
LblCurrentIndex.Text = "第<font color=#FF1D00> " + (objPage.CurrentPageIndex + 1).ToString() + " </font>页";
LblPageCount.Text = "共<font color=#FF1D00> " + objPage.PageCount.ToString() + " </font>页";
LblRecordCount.Text = "总共<font color=#FF1D00> " + ds_news.Tables[0].Rows.Count.ToString() + " </font>条";
if(CurPage>=objPage.PageCount)
{
btnNext.Enabled=false;
}
else if (CurPage<=1)
{
btnPrev.Enabled=false;
}
btnFirst.NavigateUrl=Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(1)+Session["big"].ToString();
btnNext.NavigateUrl=Request.CurrentExecutionFilePath +"?Page="+Convert.ToString(CurPage+1)+Session["big"].ToString();
btnPrev.NavigateUrl=Request.CurrentExecutionFilePath +"?Page="+Convert.ToString(CurPage-1)+Session["big"].ToString();
btnLast.NavigateUrl=Request.CurrentExecutionFilePath +"?Page="+Convert.ToString(objPage.PageCount.ToString())+Session["big"].ToString();
this.DataList1.DataSource=objPage;
this.DataList1.DataBind();
for(int i=1;i<=int.Parse(objPage.PageCount.ToString());i++)
{
string s="";
s=s+Convert.ToString(i);
this.dropnum.Items.Add(s);
}
if (ds_news.Tables[0].Rows.Count == 0)
{
btnFirst.Visible = false;
btnPrev.Visible = false;
btnNext.Visible = false;
btnLast.Visible = false;
LblCurrentIndex.Visible = false;
LblPageCount.Visible = false;
LblRecordCount.Visible = false;
}
else if (objPage.PageCount == 1)
{
btnFirst.Visible = false;
btnPrev.Visible = false;
btnNext.Visible = false;
btnLast.Visible = false;
}
}
else
{
ed.Visible = true;
btnPrev.Visible=false;
btnNext.Visible=false;
btnFirst.Visible=false;
btnLast.Visible=false;
ed.Text = "无新闻发布";
this.dropnum.Visible=false;
this.lblp.Visible=false;
this.lblz.Visible=false;
}
}
#endregion
public string SplieStr(object str,int n)
{
string s = str.ToString();
if(s.Length > n)
{
s = s.Substring(0,n)+"…";
}
return s;
}
++++++++++++++++++++
<div id="page_01">
<asp:HyperLink id="btnFirst" runat="server">首 页</asp:HyperLink>
<asp:HyperLink id="btnPrev" runat="server">上一页</asp:HyperLink>
<asp:HyperLink id="btnNext" runat="server">下一页</asp:HyperLink>
<asp:HyperLink id="btnLast" runat="server">末 页</asp:HyperLink>
<asp:Label id="LblRecordCount" runat="server"></asp:Label>
<asp:Label id="LblPageCount" runat="server"></asp:Label>
<asp:Label id="LblCurrentIndex" runat="server"></asp:Label>
<asp:Label id="lblz" runat="server">转到第</asp:Label>
<asp:DropDownList id="dropnum" runat="server" AutoPostBack="True" onselectedindexchanged="dropnum_SelectedIndexChanged"></asp:DropDownList>
<asp:Label id="lblp" runat="server">页</asp:Label>
<asp:Label id="ed" runat="server"></asp:Label>
</div>+
{
bool pageshow=true;
DataSet ds_news=Q.Qry_type_news("",bigcode,smallcode,"");
if (ds_news.Tables[0].Rows.Count>0)
{
PagedDataSource objPage = new PagedDataSource();
//设置数据源
objPage.DataSource = ds_news.Tables[0].DefaultView;
//允许分页
objPage.AllowPaging = true;
//设置每页显示的项数
objPage.PageSize = 14;
//定义变量用来保存当前页索引
int CurPage=1;
//判断是否具有页面跳转的请求
if(!pageshow)
CurPage = 1;
else if (Request.QueryString["Page"] != null)
CurPage=Convert.ToInt32(Request.QueryString["Page"]);
//设置当前页的索引
int countnumber = ds_news.Tables[0].Rows.Count;
double db = countnumber/objPage.PageSize;
int n = int.Parse(db.ToString());
if(countnumber!=objPage.PageSize*n)
{
n+=1;
}
if (n==0) n = 1;
objPage.CurrentPageIndex = CurPage-1;
LblCurrentIndex.Text = "第<font color=#FF1D00> " + (objPage.CurrentPageIndex + 1).ToString() + " </font>页";
LblPageCount.Text = "共<font color=#FF1D00> " + objPage.PageCount.ToString() + " </font>页";
LblRecordCount.Text = "总共<font color=#FF1D00> " + ds_news.Tables[0].Rows.Count.ToString() + " </font>条";
if(CurPage>=objPage.PageCount)
{
btnNext.Enabled=false;
}
else if (CurPage<=1)
{
btnPrev.Enabled=false;
}
btnFirst.NavigateUrl=Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(1)+Session["big"].ToString();
btnNext.NavigateUrl=Request.CurrentExecutionFilePath +"?Page="+Convert.ToString(CurPage+1)+Session["big"].ToString();
btnPrev.NavigateUrl=Request.CurrentExecutionFilePath +"?Page="+Convert.ToString(CurPage-1)+Session["big"].ToString();
btnLast.NavigateUrl=Request.CurrentExecutionFilePath +"?Page="+Convert.ToString(objPage.PageCount.ToString())+Session["big"].ToString();
this.DataList1.DataSource=objPage;
this.DataList1.DataBind();
for(int i=1;i<=int.Parse(objPage.PageCount.ToString());i++)
{
string s="";
s=s+Convert.ToString(i);
this.dropnum.Items.Add(s);
}
if (ds_news.Tables[0].Rows.Count == 0)
{
btnFirst.Visible = false;
btnPrev.Visible = false;
btnNext.Visible = false;
btnLast.Visible = false;
LblCurrentIndex.Visible = false;
LblPageCount.Visible = false;
LblRecordCount.Visible = false;
}
else if (objPage.PageCount == 1)
{
btnFirst.Visible = false;
btnPrev.Visible = false;
btnNext.Visible = false;
btnLast.Visible = false;
}
}
else
{
ed.Visible = true;
btnPrev.Visible=false;
btnNext.Visible=false;
btnFirst.Visible=false;
btnLast.Visible=false;
ed.Text = "无新闻发布";
this.dropnum.Visible=false;
this.lblp.Visible=false;
this.lblz.Visible=false;
}
}
#endregion
public string SplieStr(object str,int n)
{
string s = str.ToString();
if(s.Length > n)
{
s = s.Substring(0,n)+"…";
}
return s;
}
++++++++++++++++++++
<div id="page_01">
<asp:HyperLink id="btnFirst" runat="server">首 页</asp:HyperLink>
<asp:HyperLink id="btnPrev" runat="server">上一页</asp:HyperLink>
<asp:HyperLink id="btnNext" runat="server">下一页</asp:HyperLink>
<asp:HyperLink id="btnLast" runat="server">末 页</asp:HyperLink>
<asp:Label id="LblRecordCount" runat="server"></asp:Label>
<asp:Label id="LblPageCount" runat="server"></asp:Label>
<asp:Label id="LblCurrentIndex" runat="server"></asp:Label>
<asp:Label id="lblz" runat="server">转到第</asp:Label>
<asp:DropDownList id="dropnum" runat="server" AutoPostBack="True" onselectedindexchanged="dropnum_SelectedIndexChanged"></asp:DropDownList>
<asp:Label id="lblp" runat="server">页</asp:Label>
<asp:Label id="ed" runat="server"></asp:Label>
</div>+
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2009-07-24
展开全部
哈哈 还 dataview
是Gridview 不会就别装懂
搞笑
是Gridview 不会就别装懂
搞笑
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询