ASP.NET问题,datalist设置了分页,想要导出全部数据,需要怎么做呢?
如题,datalist设置了分页,我想导出全部的数据到word当中,但是现在只能导出一页的数据。貌似datalist的属性当中没有allowpage~~...
如题,datalist设置了分页,我想导出全部的数据到word当中,但是现在只能导出一页的数据。貌似datalist的属性当中没有allowpage~~
展开
4个回答
展开全部
很好
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
DBHelper db = new DBHelper();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
pagesize();
//DBHelper db = new DBHelper();
//GridView1.DataSource = db.GetAllBook();
//GridView1.DataBind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
DBHelper db = new DBHelper();
GridView1.DataSource = db.GetBook(int.Parse(TextBox1.Text));
GridView1.DataBind();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
DBHelper db = new DBHelper();
GridView1.PageIndex = e.NewPageIndex;//把新获得索引设置为当前页的索引
GridView1.DataSource = db.GetAllBook();
GridView1.DataBind();
}
public void pagesize()
{
PagedDataSource page = new PagedDataSource();//封装数据,绑定控件
page.DataSource = db.GetAllBook().Tables[0].DefaultView;//指定数据源,而datasource这个控件不能直接来绑定数据而只能绑定视图
page.AllowPaging = true;//是否启动分页
page.PageSize = 5;//行数
page.CurrentPageIndex = int.Parse(this.lbl_pagecurent.Text)-1;//设定或获取当前页的索引
lbl_count.Text =page.PageCount.ToString();//获取显示数据源中的所有项所需要的总页数
int pagecurent = int.Parse(this.lbl_pagecurent.Text);//定义一个变量来获取当前第几页(lbl_pagecurent)
GridView1.DataSource = page;//前后两句都是用来绑定数据源的
GridView1.DataBind();
//lbl_pagecurent当前第几页 lbl_count总共第几页
//LinkButton1首页 btn_prev上一页 btn_next下一页
//LinkButton4末页 TextBox2 跳转到第几页
if (pagecurent==1)
{
btn_prev.Enabled = false;
}
else
{
btn_prev.Enabled = true;
}
if (pagecurent==page.PageCount)
{
btn_next.Enabled = false;
}
else
{
btn_next.Enabled = true;
}
}
protected void btn_prev_Click(object sender, EventArgs e)
{
int i = int.Parse(this.lbl_pagecurent.Text) - 1;
this.lbl_pagecurent.Text = i.ToString();
pagesize();
}
protected void btn_next_Click(object sender, EventArgs e)
{
int i = int.Parse(this.lbl_pagecurent.Text) + 1;
this.lbl_pagecurent.Text = i.ToString();
pagesize();
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
lbl_pagecurent.Text = "1";
pagesize();
}
protected void LinkButton4_Click(object sender, EventArgs e)
{
lbl_pagecurent.Text = this.lbl_count.Text;
pagesize();
}
protected void Button3_Click(object sender, EventArgs e)
{
this.lbl_pagecurent.Text = this.TextBox2.Text;
pagesize();
这是分页的整个源代码,有的括号掉了,你自己去看一下吧
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
DBHelper db = new DBHelper();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
pagesize();
//DBHelper db = new DBHelper();
//GridView1.DataSource = db.GetAllBook();
//GridView1.DataBind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
DBHelper db = new DBHelper();
GridView1.DataSource = db.GetBook(int.Parse(TextBox1.Text));
GridView1.DataBind();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
DBHelper db = new DBHelper();
GridView1.PageIndex = e.NewPageIndex;//把新获得索引设置为当前页的索引
GridView1.DataSource = db.GetAllBook();
GridView1.DataBind();
}
public void pagesize()
{
PagedDataSource page = new PagedDataSource();//封装数据,绑定控件
page.DataSource = db.GetAllBook().Tables[0].DefaultView;//指定数据源,而datasource这个控件不能直接来绑定数据而只能绑定视图
page.AllowPaging = true;//是否启动分页
page.PageSize = 5;//行数
page.CurrentPageIndex = int.Parse(this.lbl_pagecurent.Text)-1;//设定或获取当前页的索引
lbl_count.Text =page.PageCount.ToString();//获取显示数据源中的所有项所需要的总页数
int pagecurent = int.Parse(this.lbl_pagecurent.Text);//定义一个变量来获取当前第几页(lbl_pagecurent)
GridView1.DataSource = page;//前后两句都是用来绑定数据源的
GridView1.DataBind();
//lbl_pagecurent当前第几页 lbl_count总共第几页
//LinkButton1首页 btn_prev上一页 btn_next下一页
//LinkButton4末页 TextBox2 跳转到第几页
if (pagecurent==1)
{
btn_prev.Enabled = false;
}
else
{
btn_prev.Enabled = true;
}
if (pagecurent==page.PageCount)
{
btn_next.Enabled = false;
}
else
{
btn_next.Enabled = true;
}
}
protected void btn_prev_Click(object sender, EventArgs e)
{
int i = int.Parse(this.lbl_pagecurent.Text) - 1;
this.lbl_pagecurent.Text = i.ToString();
pagesize();
}
protected void btn_next_Click(object sender, EventArgs e)
{
int i = int.Parse(this.lbl_pagecurent.Text) + 1;
this.lbl_pagecurent.Text = i.ToString();
pagesize();
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
lbl_pagecurent.Text = "1";
pagesize();
}
protected void LinkButton4_Click(object sender, EventArgs e)
{
lbl_pagecurent.Text = this.lbl_count.Text;
pagesize();
}
protected void Button3_Click(object sender, EventArgs e)
{
this.lbl_pagecurent.Text = this.TextBox2.Text;
pagesize();
这是分页的整个源代码,有的括号掉了,你自己去看一下吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
在导出数据的时候,重新采取无分页查询。然后进行导出操作。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
分页中,传递的参数是第几页,每页多少条记录,你把页数传递为1,记录数传递为9999999等很大值就行,其它代码不用调整
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
那你在导出时使用无分布的方法呀
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询