本文整理汇总了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();
}
示例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();
}