本文整理汇总了C#中GridView.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# GridView.Dispose方法的具体用法?C# GridView.Dispose怎么用?C# GridView.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GridView
的用法示例。
在下文中一共展示了GridView.Dispose方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExportDataToExcel
/// <summary>
/// Returns string for a Given Dataset Values
/// </summary>
/// <param name="ds"></param>
/// <param name="exportColumnHeadings"></param>
public void ExportDataToExcel(string strFileName, GridView gridViewControl)
{
Response.Clear();
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment; filename=" + strFileName);
// Set as Excel as the primary format
Response.AddHeader("Content-Type", "application/Excel");
Response.ContentType = "application/Excel";
System.IO.StringWriter sw = new System.IO.StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
gridViewControl.RenderControl(htw);
Response.Write(sw.ToString());
//
gridViewControl.Dispose();
Response.End();
}
示例2: WriteToXls2
/// <summary>
/// 匯出轉單
/// </summary>
/// <param name="dtData"></param>
/// <param name="strFileName"></param>
public void WriteToXls2(DataTable dtData, string strFileName)
{
#region
GridView gvExport = new GridView();
try
{
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=" +
HttpUtility.UrlEncode(strFileName.Replace(".xls", ""), System.Text.UTF8Encoding.UTF8) + ".xls");
Response.ContentType = "application/vnd.ms-excel;charset='utf-8'";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("BIG5");
this.EnableViewState = false;
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
gvExport.DataSource = dtData;
gvExport.DataBind();
gvExport.RenderControl(oHtmlTextWriter);
Response.Write(@"<style>td{mso-number-format:\@}</style>");
Response.Write(oStringWriter.ToString());
Response.Flush();
Response.End();
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "", string.Format("alert('{0}');", ex.Message), true);
}
finally
{
gvExport.Dispose();
}
#endregion
}
示例3: WriteToXls
/// <summary>
/// 輸出為EXCEL
/// </summary>
public void WriteToXls()
{
#region
GridView gvExcel = new GridView();
gvExcel.RowDataBound += new GridViewRowEventHandler(gvExcel_RowDataBound);
try
{
ALOModel.MaintainStoreRank BCO = new ALOModel.MaintainStoreRank(ConnectionDB);
DataTable dtExcel = null;
string SessionIDName = string.Format("{0}_{1}_EXCELDATA", PAGE_DT_01, PageTimeStamp.Value);
//匯出筆數上限
Int32 iLimitedRowsCounts = 65535;
if (BCO.CheckExcelOutCount(GetInputValues(), iLimitedRowsCounts))
{
dtExcel = BCO.QueryStorRankForExcel2_2(GetInputValues());
if (dtExcel != null && dtExcel.Rows.Count > 0)
{
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=" +
HttpUtility.UrlEncode(txt_ExportFileName.Text.Trim().ToLower().Replace(".xls", ""), System.Text.UTF8Encoding.UTF8) + ".xls");
Response.ContentType = "application/vnd.ms-excel;charset='utf-8'";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("BIG5");
this.EnableViewState = false;
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
gvExcel.AllowPaging = false;
gvExcel.AllowSorting = false;
gvExcel.DataSource = dtExcel;
gvExcel.DataBind();
gvExcel.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.Flush();
Response.End();
}
else
{
ResultMsgLabel.Text = "無匯出資料";
}
}
else
{
throw new Exception("匯出筆數超過上限" + iLimitedRowsCounts.ToString() + "筆");
}
}
catch (Exception ex)
{
ErrorMsgLabel.Text = ex.Message;
}
finally
{
gvExcel.DataSource = null;
gvExcel.Dispose();
}
#endregion
}