当前位置: 首页>>代码示例>>C#>>正文


C# GridView.Dispose方法代码示例

本文整理汇总了C#中System.Web.UI.WebControls.GridView.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# GridView.Dispose方法的具体用法?C# GridView.Dispose怎么用?C# GridView.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.UI.WebControls.GridView的用法示例。


在下文中一共展示了GridView.Dispose方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: btnExportExcel_Click

        protected void btnExportExcel_Click(object sender, EventArgs e)
        {
            GridView gvclaimxuat = new GridView();
            DataTable dt = new DataTable();
            string id = cldao.LayMaTheoTen(lblThamChieuHead.Text);
            dt = cldao.XuatClaim(id);
            int dem = dt.Rows.Count;
            gvclaimxuat.DataSource = dt;
            gvclaimxuat.DataBind();
            //Export(dt, "Claim", lblThamChieuHead.Text);
            ExportToExcel(lblThamChieuHead.Text + ".xls", gvclaimxuat);

            gvclaimxuat = null;
            gvclaimxuat.Dispose();
        }
开发者ID:DinhHue,项目名称:savvyplatform,代码行数:15,代码来源:InformationForm.aspx.cs

示例2: ExportToExcel

        /// <summary>
        ///     导出GridView中的数据到Excel
        /// </summary>
        /// <param name="gvw"></param>
        /// <param name="title"></param>
        /// <param name="TableName"></param>
        private static void ExportToExcel(GridView gvw, string title, string TableName) {
            //int coun = ExistsRegedit();
            //string fileName = string.Format("DataInfo{0:yyyy-MM-dd_HH_mm}.xls", DateTime.Now);
            //if (coun >0)
            //{
            //    fileName = string.Format("DataInfo{0:yyyy-MM-dd_HH_mm}.xls", DateTime.Now);
            //    //HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF7;
            //}
            //else
            //{
            //    HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
            //    //Page.RegisterStartupScript("mess", "<script>alert('该机器没有安装任何office软件');</script>");
            //    //return;
            //}

            for (var i = 0; i < gvw.Rows.Count; i++) {
                for (var j = 0; j < gvw.HeaderRow.Cells.Count; j++) {
                    //这里给指定的列编辑格式,将数字输出为文本,防止数字溢出  
                    gvw.Rows[i].Cells[j].Attributes.Add("style", "vnd.ms-excel.numberformat:@");
                    //nowrap="nowrap" 不换行
                    gvw.Rows[i].Cells[j].Attributes.Add("nowrap", "nowrap");
                }
            }
            HttpContext.Current.Response.Buffer = true;
            HttpContext.Current.Response.ClearContent();
            HttpContext.Current.Response.ClearHeaders();
            //fileName = string.Format("DataInfo{0:yyyy-MM-dd_HH_mm}.xls", DateTime.Now);
            HttpContext.Current.Response.AppendHeader("Content-Disposition",
                "attachment;filename=" + HttpUtility.UrlEncode(TableName) + HttpUtility.UrlEncode(title) + ".xls");
            HttpContext.Current.Response.Charset = "UTF-8";
            HttpContext.Current.Response.ContentEncoding = Encoding.GetEncoding("GB2312");


            HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
            var tw = new StringWriter();

            var hw = new HtmlTextWriter(tw);

            gvw.RenderControl(hw);
            if (!string.IsNullOrEmpty(title)) {
                HttpContext.Current.Response.Write("<b><center><font size=3 face=Verdana color=#0000FF>" + title +
                                                   "</font></center></b>");
            }
            HttpContext.Current.Response.Write(tw.ToString());
            HttpContext.Current.Response.Flush();
            //HttpContext.Current.Response.Close();
            HttpContext.Current.Response.End();
            gvw.Dispose();
            tw.Dispose();
            hw.Dispose();
        }
开发者ID:kangwl,项目名称:DotNet.Mix,代码行数:57,代码来源:ExcelExport.cs


注:本文中的System.Web.UI.WebControls.GridView.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。