我的repeater有分页,当我导出数据的时候为什么只导出了第一页的数据导出方法
protected void ibtn_Excel_Click(object sender, ImageClickEventArgs e)
{
Response.Clear();
Response.Buffer = true;
Response.Charset = "utf-8";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("名称", System.Text.Encoding.UTF8) + ".xls");
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312"); //设置输出流为简体中文
Response.ContentType = "application/ms-excel"; //设置输出文件类型为excel文件。
this.EnableViewState = false;
System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN", true);
System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad);
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
// repeater控件的ID
this.rpt_CEO.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();
}后台类中的代码
#region CEO报表查询
/// <summary>
/// CEO报表查询
/// </summary>
/// <param name="timeBegin"></param>
/// <param name="timeEnd"></param>
/// <param name="page"></param>
public void GetCEO(string timeBegin, string timeEnd, Page page)
{
try
{
Repeater rpt_CEO = (Repeater)page.FindControl("rpt_CEO");
DataSet ds;
//= ViewState["DtDatat"] as DataTable;
int ThisPage = PublicClass.thispages();
if (ThisPage < 1) ThisPage = 1;
int pages = 0;
int recordcount = 0;
string WhereStr = "order_CreTime between '" + timeBegin + "'" + " and '" + timeEnd + "' and order_Status = 10";//接收参数语句
string text = Request.GetUrlPamars("text");
string WhereUrl = "Financial_Reports.aspx?text=" + text;
List<string[]> OutList = new List<string[]>();
object[] Params = new object[11];
Params[0] = "Hotel_Order";//表名
Params[1] = "order_Id";//按该列来进行分页
Params[2] = "order_Id";//按该列来进行排序
Params[3] = 0;//列的类型
Params[4] = 0;//分页列排序,0-顺序,1-倒序 ;
Params[5] = 0;//排序列排序,0-顺序,1-倒序
Params[6] = "*";//要查询出的字段列
Params[7] = 1;//每页记录数
Params[8] = ThisPage;//指定页
Params[9] = WhereStr;//条件
Params[10] = "Pagination";//分页存储过程名 //0:@tb varchar(100), --表名 ; 1:@col varchar(50), --按该列来进行分页; 2:@col1 varchar(50), --按该列来进行排序 ; 3:@coltype int, --@col列的类型,0-数字类型,1-字符类型,2-日期时间类型 ; 4:@orderby bit, --分页列排序,0-顺序,1-倒序 ; 5:@orderby1 bit, --排序列排序,0-顺序,1-倒序 ; 6:@collist varchar(800),--要查询出的字段列表,*表示全部字段 ; 7:@pagesize int, --每页记录数 ; 8:@page int, --指定页 ; 9:@condition varchar(800),--查询条件 ; 10:存储过程名
ds = Provider.DataSetList(true, out OutList, Params);
rpt_CEO.DataSource = ds.Tables[0];
rpt_CEO.DataBind(); for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
Literal l1 = (Literal)rpt_CEO.Items[i].FindControl("l1"); //序号
Literal l2 = (Literal)rpt_CEO.Items[i].FindControl("l2"); //酒店名称
Literal l3 = (Literal)rpt_CEO.Items[i].FindControl("l3"); //房型
Literal l4 = (Literal)rpt_CEO.Items[i].FindControl("l4"); //入住人姓名
Literal l5 = (Literal)rpt_CEO.Items[i].FindControl("l5"); //入住时间
Literal l6 = (Literal)rpt_CEO.Items[i].FindControl("l6"); //离店时间
Literal l7 = (Literal)rpt_CEO.Items[i].FindControl("l7"); //间数
Literal l8 = (Literal)rpt_CEO.Items[i].FindControl("l8"); //几晚
Literal l9 = (Literal)rpt_CEO.Items[i].FindControl("l9"); //应收金额
Literal l10 = (Literal)rpt_CEO.Items[i].FindControl("l10"); //实际入住时间
Literal l11 = (Literal)rpt_CEO.Items[i].FindControl("l11"); //实际离店时间
Literal l12 = (Literal)rpt_CEO.Items[i].FindControl("l12"); //实收金额
Literal l13 = (Literal)rpt_CEO.Items[i].FindControl("l13"); //联系方式
Literal l14 = (Literal)rpt_CEO.Items[i].FindControl("l14"); //联系人姓名 l1.Text = "" + (i + 1);
l2.Text = ds.Tables[0].Rows[i]["hotel_Name"].ToString();
l3.Text = ds.Tables[0].Rows[i]["roomType_Name"].ToString();
l4.Text = ds.Tables[0].Rows[i]["checkInName"].ToString();
l5.Text = Convert.ToDateTime(ds.Tables[0].Rows[i]["checkInTime"]).ToString("yyyy-MM-dd");
l6.Text = Convert.ToDateTime(ds.Tables[0].Rows[i]["cheOutTime"]).ToString("yyyy-MM-dd");
l7.Text = ds.Tables[0].Rows[i]["resRoomQuantity"].ToString();
l8.Text = ds.Tables[0].Rows[i]["resFate"].ToString();
l9.Text = Convert.ToInt32(ds.Tables[0].Rows[i]["totalPaid"]).ToString();
l10.Text = Convert.ToDateTime(ds.Tables[0].Rows[i]["OKcheckInTime"]).ToString("yyyy-MM-dd");
l11.Text = Convert.ToDateTime(ds.Tables[0].Rows[i]["OKcheOutTime"]).ToString("yyyy-MM-dd");
l12.Text = Convert.ToInt32(ds.Tables[0].Rows[i]["realityPrice"]).ToString();
l13.Text = ds.Tables[0].Rows[i]["resPhone"].ToString();
l14.Text = ds.Tables[0].Rows[i]["resName"].ToString();
} for (int i = 0; i < OutList.Count; i++)
{
if (OutList[i][0] == "@pages")
{
pages = int.Parse(OutList[i][1]);
}
if (OutList[i][0] == "@recordcounts")
{
recordcount = int.Parse(OutList[i][1]);
}
}
Literal pageli = (Literal)page.FindControl("pageli");
pageli.Text = PublicClass.PageNumber(pages, recordcount, ThisPage, 5, WhereUrl);
}
catch (Exception ex)
{
ExceptionHander.FxtxException(0, ex.Message, "SysBulletinMange", ex);
}
}
#endregion这个框架是别人写好的7层 分为前台和后台两个ui层 高人指点迷津 高分送上
protected void ibtn_Excel_Click(object sender, ImageClickEventArgs e)
{
Response.Clear();
Response.Buffer = true;
Response.Charset = "utf-8";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("名称", System.Text.Encoding.UTF8) + ".xls");
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312"); //设置输出流为简体中文
Response.ContentType = "application/ms-excel"; //设置输出文件类型为excel文件。
this.EnableViewState = false;
System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN", true);
System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad);
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
// repeater控件的ID
this.rpt_CEO.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();
}后台类中的代码
#region CEO报表查询
/// <summary>
/// CEO报表查询
/// </summary>
/// <param name="timeBegin"></param>
/// <param name="timeEnd"></param>
/// <param name="page"></param>
public void GetCEO(string timeBegin, string timeEnd, Page page)
{
try
{
Repeater rpt_CEO = (Repeater)page.FindControl("rpt_CEO");
DataSet ds;
//= ViewState["DtDatat"] as DataTable;
int ThisPage = PublicClass.thispages();
if (ThisPage < 1) ThisPage = 1;
int pages = 0;
int recordcount = 0;
string WhereStr = "order_CreTime between '" + timeBegin + "'" + " and '" + timeEnd + "' and order_Status = 10";//接收参数语句
string text = Request.GetUrlPamars("text");
string WhereUrl = "Financial_Reports.aspx?text=" + text;
List<string[]> OutList = new List<string[]>();
object[] Params = new object[11];
Params[0] = "Hotel_Order";//表名
Params[1] = "order_Id";//按该列来进行分页
Params[2] = "order_Id";//按该列来进行排序
Params[3] = 0;//列的类型
Params[4] = 0;//分页列排序,0-顺序,1-倒序 ;
Params[5] = 0;//排序列排序,0-顺序,1-倒序
Params[6] = "*";//要查询出的字段列
Params[7] = 1;//每页记录数
Params[8] = ThisPage;//指定页
Params[9] = WhereStr;//条件
Params[10] = "Pagination";//分页存储过程名 //0:@tb varchar(100), --表名 ; 1:@col varchar(50), --按该列来进行分页; 2:@col1 varchar(50), --按该列来进行排序 ; 3:@coltype int, --@col列的类型,0-数字类型,1-字符类型,2-日期时间类型 ; 4:@orderby bit, --分页列排序,0-顺序,1-倒序 ; 5:@orderby1 bit, --排序列排序,0-顺序,1-倒序 ; 6:@collist varchar(800),--要查询出的字段列表,*表示全部字段 ; 7:@pagesize int, --每页记录数 ; 8:@page int, --指定页 ; 9:@condition varchar(800),--查询条件 ; 10:存储过程名
ds = Provider.DataSetList(true, out OutList, Params);
rpt_CEO.DataSource = ds.Tables[0];
rpt_CEO.DataBind(); for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
Literal l1 = (Literal)rpt_CEO.Items[i].FindControl("l1"); //序号
Literal l2 = (Literal)rpt_CEO.Items[i].FindControl("l2"); //酒店名称
Literal l3 = (Literal)rpt_CEO.Items[i].FindControl("l3"); //房型
Literal l4 = (Literal)rpt_CEO.Items[i].FindControl("l4"); //入住人姓名
Literal l5 = (Literal)rpt_CEO.Items[i].FindControl("l5"); //入住时间
Literal l6 = (Literal)rpt_CEO.Items[i].FindControl("l6"); //离店时间
Literal l7 = (Literal)rpt_CEO.Items[i].FindControl("l7"); //间数
Literal l8 = (Literal)rpt_CEO.Items[i].FindControl("l8"); //几晚
Literal l9 = (Literal)rpt_CEO.Items[i].FindControl("l9"); //应收金额
Literal l10 = (Literal)rpt_CEO.Items[i].FindControl("l10"); //实际入住时间
Literal l11 = (Literal)rpt_CEO.Items[i].FindControl("l11"); //实际离店时间
Literal l12 = (Literal)rpt_CEO.Items[i].FindControl("l12"); //实收金额
Literal l13 = (Literal)rpt_CEO.Items[i].FindControl("l13"); //联系方式
Literal l14 = (Literal)rpt_CEO.Items[i].FindControl("l14"); //联系人姓名 l1.Text = "" + (i + 1);
l2.Text = ds.Tables[0].Rows[i]["hotel_Name"].ToString();
l3.Text = ds.Tables[0].Rows[i]["roomType_Name"].ToString();
l4.Text = ds.Tables[0].Rows[i]["checkInName"].ToString();
l5.Text = Convert.ToDateTime(ds.Tables[0].Rows[i]["checkInTime"]).ToString("yyyy-MM-dd");
l6.Text = Convert.ToDateTime(ds.Tables[0].Rows[i]["cheOutTime"]).ToString("yyyy-MM-dd");
l7.Text = ds.Tables[0].Rows[i]["resRoomQuantity"].ToString();
l8.Text = ds.Tables[0].Rows[i]["resFate"].ToString();
l9.Text = Convert.ToInt32(ds.Tables[0].Rows[i]["totalPaid"]).ToString();
l10.Text = Convert.ToDateTime(ds.Tables[0].Rows[i]["OKcheckInTime"]).ToString("yyyy-MM-dd");
l11.Text = Convert.ToDateTime(ds.Tables[0].Rows[i]["OKcheOutTime"]).ToString("yyyy-MM-dd");
l12.Text = Convert.ToInt32(ds.Tables[0].Rows[i]["realityPrice"]).ToString();
l13.Text = ds.Tables[0].Rows[i]["resPhone"].ToString();
l14.Text = ds.Tables[0].Rows[i]["resName"].ToString();
} for (int i = 0; i < OutList.Count; i++)
{
if (OutList[i][0] == "@pages")
{
pages = int.Parse(OutList[i][1]);
}
if (OutList[i][0] == "@recordcounts")
{
recordcount = int.Parse(OutList[i][1]);
}
}
Literal pageli = (Literal)page.FindControl("pageli");
pageli.Text = PublicClass.PageNumber(pages, recordcount, ThisPage, 5, WhereUrl);
}
catch (Exception ex)
{
ExceptionHander.FxtxException(0, ex.Message, "SysBulletinMange", ex);
}
}
#endregion这个框架是别人写好的7层 分为前台和后台两个ui层 高人指点迷津 高分送上
//dataset导出excel
public static void CreateExcel(DataSet ds, string FileName)
{
//resp = Page.Response;
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8) + ".xls");
HttpContext.Current.Response.ContentType = "application/ms-excel";
string colHeaders = "", ls_item = "";
int i = 0; //定义表对象与行对像,同时用DataSet对其值进行初始化
System.Data.DataTable dt = ds.Tables[0];
DataRow[] myRow = dt.Select("");
//取得数据表各列标题,各标题之间以\t分割,最后一个列标题后加回车符
for (i = 0; i < dt.Columns.Count - 1; i++)
colHeaders += dt.Columns[i].Caption.ToString() + "\t";
colHeaders += dt.Columns[i].Caption.ToString() + "\n";
//向HTTP输出流中写入取得的数据信息
HttpContext.Current.Response.Write(colHeaders);
//逐行处理数据
foreach (DataRow row in myRow)
{
//在当前行中,逐列获得数据,数据之间以\t分割,结束时加回车符\n
for (i = 0; i < dt.Columns.Count - 1; i++)
ls_item += row[i].ToString() + "\t";
ls_item += row[i].ToString() + "\n";
//当前行数据写入HTTP输出流,并且置空ls_item以便下行数据
HttpContext.Current.Response.Write(ls_item);
ls_item = "";
}
//写缓冲区中的数据到HTTP头文件中
HttpContext.Current.Response.End();
}
假设:项目上线之后一天的数据就可能有几百条 要一页一页导出的话.....CEO手没半个月就废掉了~~
rpt_CEO.AllowPaging = false;
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(sw);
this.OrderList.RenderControl(hw); Response.Clear();
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
Page.EnableViewState = false; Response.AppendHeader("Content-Disposition", "attachment;filename=Teacher.xls");
Response.Write("<html><head><meta http-equiv=Content-Type content=\"text/html; charset=GB2312\"><title>Copyright by SDU</title></head><body><center>"); //出现乱码的话需要把GB2312换成auto
Response.Write(sw.ToString());
Response.Write("</center></body></html>");
Response.End();