日期:2014-05-18  浏览次数:20441 次

怎样实现用按钮实现分页功能
用c#,这个问题不难,希望大家帮助,最好有代码

------解决方案--------------------
PagedDataSource objpage = new PagedDataSource();
objpage.DataSource = ds.Tables[ "news "].DefaultView;
//设置允许分页
objpage.AllowPaging = true;
//设置每页项数
objpage.PageSize = 15;
pagesize = objpage.PageSize;
//定义当前页索引
int curpage;
if(Request.QueryString[ "page "] != null)
{
if(Convert.ToInt32(Request.QueryString[ "page "]) > objpage.PageCount)
{
curpage = objpage.PageCount;
}
else
{
curpage = Convert.ToInt32(Request.QueryString[ "page "]);
}
}
else
{
curpage = 1;
}
objpage.CurrentPageIndex = curpage-1;
first.NavigateUrl = Request.CurrentExecutionFilePath + "?page=1&csort= "+csort+ "&keyword= "+keyword+ "&sea_type= "+sea_type+ "&sea_term= "+sea_term;
if(!objpage.IsFirstPage)
{
previous.NavigateUrl = Request.CurrentExecutionFilePath + "?page= " + (curpage-1) + "&csort= "+csort+ "&keyword= "+keyword+ "&sea_type= "+sea_type+ "&sea_term= "+sea_term;
}
if(!objpage.IsLastPage)
{
next.NavigateUrl = Request.CurrentExecutionFilePath + "?page= " +(curpage+1) + "&csort= "+csort+ "&keyword= "+keyword+ "&sea_type= "+sea_type+ "&sea_term= "+sea_term;
}
last.NavigateUrl = Request.CurrentExecutionFilePath + "?page= " +objpage.PageCount + "&csort= "+csort+ "&keyword= "+keyword+ "&sea_type= "+sea_type+ "&sea_term= "+sea_term;
Label1.Text = curpage.ToString();
Label2.Text = objpage.PageCount.ToString();
Label3.Text = objpage.DataSourceCount.ToString();
Label4.Text = objpage.PageSize.ToString();
pagetext.Value = curpage.ToString();
DataGrid1.DataSource = objpage;
DataGrid1.DataBind();
int i;
for(i=0;i <DataGrid1.Items.Count;i++)
{
DataGrid1.Items[i].Attributes.Add( "style ", "cursor:hand; ");
DataGrid1.Items[i].Attributes.Add( "onmouseover ", "this.style.backgroundColor= '#C1D2EE '; ");
DataGrid1.Items[i].Attributes.Add( "onmouseout ", "this.style.backgroundColor= '#ffffff '; ");
}
ds.Clear();
ds.Dispose();


private void pagegoto_ServerClick(object sender, EventArgs e)
{
string page1 = pagetext.Value.Trim();
string url;
if(page1 != " ")
{
url = "admin_info.aspx?page= " + page1 + "&csort= "+Request.QueryString[ "csort "]+ "&keyword= "+Request.QueryString[ "keyword "]+ "&sea_type= "+Request.QueryString[ "sea_type "]+ "&sea_term= "+Request.QueryString[ "sea_term "];
}
else
{
url = "admin_info.aspx?page=1&csort= "+Request.QueryString[ "csort "]+ "&keyword= "+Request.QueryString[ "keyword "]+ "&sea_type= "+Request.QueryString[ "sea_type "]+ "&sea_term= "+Request.QueryString[ "sea_term "];
}
Response.Redirect(url);
}
------解决方案--------------------
前台:
<p align= "center "> <asp:hyperlink id= "first " runat= "server "