GridView Export Excel and set display column visible status
来源:互联网 发布:mac侧边栏图标异常 编辑:程序博客网 时间:2024/05/22 06:37
using System.Text;
using System.IO;
protected void lbnExport_Click(object sender, EventArgs e)
{
PrepareGridViewForExport(gridViewReport);
ExportGridView();
}
/// <summary>
///
/// </summary>
private void ExportGridView()
{
string attachment = "attachment; filename=Report.xls";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
GridView formatGridView = gridViewReport;
formatGridView.Columns[5].Visible = true;
formatGridView.Columns[6].Visible = true;
formatGridView.Columns[9].Visible = true;
formatGridView.Columns[11].Visible = true;
formatGridView.Columns[12].Visible = true;
formatGridView.RenderControl(htw);
//gridViewReport.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
public override void VerifyRenderingInServerForm(Control control)
{
}
private void PrepareGridViewForExport(Control gv)
{
LinkButton lb = new LinkButton();
Literal l = new Literal();
string name = String.Empty;
for (int i = 0; i < gv.Controls.Count; i++)
{
if (gv.Controls[i].GetType() == typeof(LinkButton))
{
l.Text = (gv.Controls[i] as LinkButton).Text;
gv.Controls.Remove(gv.Controls[i]);
gv.Controls.AddAt(i, l);
}
else if (gv.Controls[i].GetType() == typeof(DropDownList))
{
l.Text = (gv.Controls[i] as DropDownList).SelectedItem.Text;
gv.Controls.Remove(gv.Controls[i]);
gv.Controls.AddAt(i, l);
}
else if (gv.Controls[i].GetType() == typeof(CheckBox))
{
l.Text = (gv.Controls[i] as CheckBox).Checked ? "True" : "False";
gv.Controls.Remove(gv.Controls[i]);
gv.Controls.AddAt(i, l);
}
if (gv.Controls[i].HasControls())
{
PrepareGridViewForExport(gv.Controls[i]);
}
}
}
- GridView Export Excel and set display column visible status
- Export GridView to Excel
- Export GridView with Images from database to Word Excel and PDF Formats
- Fast Excel import and export
- Export GridView to Excel within an UpdatePanel
- export DISPLAY
- alter table t_agent_adv alter column status set default 1;
- export grid to excel fast and wyswyg
- export grid to excel fast and wyswyg
- smartGWT, OSGi export to excel and PDF
- Set row and column to 1's
- disabled、display、visible区别
- Export ASP.NET Gridview data into MS-Excel sheet
- Export Data from GridView to Excel, Word, HTML with C#
- Export large data from GridView to Excel file using C#
- 详解 EXPORT DISPLAY
- export DISPLAY=:0
- EXCEL Export
- 分组加密模式浅析[整理]
- 搞定乱码
- 惰性动态Action表单
- activex 部件不能创建对象,c/ windows/ system32 /Platman_install.vbs 错误
- Linux的栈大小
- GridView Export Excel and set display column visible status
- vs2005编译QT4.5版本
- windows右键打开命令行窗口
- json是什么
- request.getSession()
- POJ 1971 Parallelogram Counting 解题报告
- Java基本文件操作大全
- 数据库序列号自动生成。
- JSP文件上传