首页 ┆ 网站地图 ┆ 在线留言 ┆ 游戏资讯 ┆ 资源下载 ┆ 端午节祝福 ┆ 迅雷在线影视 ┆淘宝手机在线充值 ┆淘宝游戏点卡充值 
设为首页
加入收藏
联系我们
高级搜索
您当前的位置: 主页>NET专区>.NET2.0>gridview表头固定并实现打印到excel功能代码
gridview表头固定并实现打印到excel功能代码
来源: 发布时间:2008-03-10 发布人: 浏览: 人次   字体: [ ]  


    
protected void Button1_Click(object sender, EventArgs e)
    
{
        Response.Clear();
        Response.Buffer 
= true;
        Response.Charset 
= "GB2312";
        Response.AppendHeader(
"Content-Disposition""attachment;filename=FileName.xls");
        
// 如果设置为 GetEncoding("GB2312");导出的文件将会出现乱码!!!
        Response.ContentEncoding = System.Text.Encoding.UTF7;
        Response.ContentType 
= "application/ms-excel";//设置输出文件类型为excel文件。 
        System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
         //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);
        
this.GridView1.RenderControl(oHtmlTextWriter);
        Response.Output.Write(oStringWriter.ToString());
        Response.Flush();
        Response.End();

    }

    
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    
{
        
if (e.Row.RowType == DataControlRowType.DataRow)
        
{
            
e.Item.Cells[0].Attributes.Add("style","vnd.ms-excel.numberformat:@");
             e.Item.Cells[3].Attributes.Add("style","vnd.ms-excel.numberformat:¥#,###.00");

        }

    }


    
public override void VerifyRenderingInServerForm(Control control)
    
{ }
}


共2页: 上一页 [1] 2 下一页
相 关 文 章   发布商链接
·重写GridView实现单击行变色的效果代...
·图解ASP.NET下AJAX安装(VS2005下安...
·Gridview控件字段内容过长的解决方法...
·实例解决GridView中弹出对话框并改变...
·Net2.0中使用母版页及其母版页的控件
·为GridView控件添加分页导航条形式代...
·GridView中固定列的两种方法
·DataView对象获取数据行相应列值的两...
·VS2005利用TreeView控件和递归函数动...
·GridView通过模板列实现第一列显示出...
 §最新评论:(评论内容只代表网友观点,与本站立场无关!)
网名: 验证码:  【所有评论】【↑返回顶部
评 分: 12 345
评论内容:(不能超过500字,请自觉遵守互联网相关政策法规。[按 Ctrl+Enter 可直接提交]
注意:请勿在本站发布政治话题、色情及违反法律的内容。
IT知道网 声明:刊登此文章是为了传递更多信息,文章内容仅供参考,转载请注明出处。
推 荐 文 章
·实例讲解在.net2.0中对config
·包含32种常见的用户输入验证...
·asp.net不使用服务器控件的情
·如何更改单个aspx页面的编码...
·实例讲解如何设置gridview的...
·asp.NET 2.0中引发CSS失效问...
·GridView通过模板列实现第一...
·VS2005利用TreeView控件和递...
·DataView对象获取数据行相应...
·GridView中固定列的两种方法
·为GridView控件添加分页导航...
·Net2.0中使用母版页及其母版...
·实例解决GridView中弹出对话...
·Gridview控件字段内容过长的...
·图解ASP.NET下AJAX安装(VS20...
热 门 文 章
·asp.net(C#)弹出窗口返回值并...
·VS2005利用Excel组件操作Exce...
·AJAX实现无刷新适时显示gridV...
·Js获取radiobuttonlist选中值...
·gridview绑定数据显示的各种...
·ASP.NET中“无法加载 DLL 找...
·asp.net文件下载防止乱码出现...
·asp.net2.0回发或回调参数无...
·实现gridview内容打印功能的...
·ASP.NET多个用户控件回车提交...
·Asp.net页面传递参数的几种方...
·图解ASP.NET下AJAX安装(VS20...
·实例解决GridView中弹出对话...
·如何在asp.net中获取GridView...
·asp.net中GridView每个单元格...
网站首页 - 关于本站 - 加入收藏 - 网站地图 - 友情连接 - 在线留言 - 联系我们 - 返回顶部
Copyright © 2007 IT知道网.[冀ICP备07026896号]. All Rights Reserved .