本文整理汇总了C#中Page.RenderControl方法的典型用法代码示例。如果您正苦于以下问题:C# Page.RenderControl方法的具体用法?C# Page.RenderControl怎么用?C# Page.RenderControl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Page
的用法示例。
在下文中一共展示了Page.RenderControl方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Button3_Click
protected void Button3_Click(object sender, EventArgs e)
{
string fileName = "export.xls";
System.Text.StringBuilder sb = new System.Text.StringBuilder();
System.IO.StringWriter sw = new System.IO.StringWriter(sb);
HtmlTextWriter htw = new HtmlTextWriter(sw);
Page page = new Page();
HtmlForm form = new HtmlForm();
// Deshabilitar la validación de eventos, sólo asp.net 2
page.EnableEventValidation = false;
// Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD.
page.DesignerInitialize();
page.Controls.Add(form);
form.Controls.Add(GridView1);
page.RenderControl(htw);
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
Response.Charset = "UTF-8";
Response.ContentEncoding = System.Text.Encoding.Default;
Response.Write(sb.ToString());
Response.End();
}
示例2: PrintWebControl
public static void PrintWebControl(Control ctrl, string Script)
{
StringWriter stringWrite = new StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new System.Web.UI.HtmlTextWriter(stringWrite);
if (ctrl is WebControl)
{
Unit w = new Unit(100, UnitType.Percentage); ((WebControl)ctrl).Width = w;
}
Page pg = new Page();
pg.EnableEventValidation = false;
if (Script != string.Empty)
{
pg.ClientScript.RegisterStartupScript(pg.GetType(), "PrintJavaScript", Script);
}
HtmlForm frm = new HtmlForm();
pg.Controls.Add(frm);
frm.Attributes.Add("runat", "server");
frm.Controls.Add(ctrl);
pg.DesignerInitialize();
pg.RenderControl(htmlWrite);
string strHTML = stringWrite.ToString();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Write(strHTML);
HttpContext.Current.Response.Write("<script>window.print();</script>");
HttpContext.Current.Response.End();
}
示例3: RenderControl
public static string RenderControl(Control c)
{
StringBuilder sb = new StringBuilder();
StringWriter tw = new StringWriter(sb);
HtmlTextWriter hw = new HtmlTextWriter(tw);
HtmlForm form = new FakeHtmlForm();
Page page = new Page();
page.EnableViewState = false;
form.Controls.Add(c);
page.Controls.Add(form);
page.RenderControl(hw);
return sb.ToString();
}
示例4: btnExport_Click
protected void btnExport_Click(object sender, EventArgs e)
{
Security s= Session["sec"] as Security;
if (s==null)
{
Response.Redirect("error.aspx");
}
string jsid = s.getUserCode();
dbModule dm = new dbModule();
string kcbh = KCDDL.SelectedValue;
int syid= Convert.ToInt32(SYDDL.SelectedValue);
DataTable dt = dm.getSyqdqk( kcbh ,syid,jsid );
GridView1.DataSource = dt;
GridView1.DataBind();
GridView1.Caption = KCDDL.SelectedItem.Text + "---" + SYDDL.SelectedItem.Text + "签到情况";
string fileName = "export.xls";
System.Text.StringBuilder sb = new System.Text.StringBuilder();
System.IO.StringWriter sw = new System.IO.StringWriter(sb);
HtmlTextWriter htw = new HtmlTextWriter(sw);
Page page = new Page();
HtmlForm form = new HtmlForm();
// Deshabilitar la validación de eventos, sólo asp.net 2
page.EnableEventValidation = false;
// Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD.
page.DesignerInitialize();
page.Controls.Add(form);
form.Controls.Add(GridView1);
page.RenderControl(htw);
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
Response.Charset = "UTF-8";
Response.ContentEncoding = System.Text.Encoding.Default;
Response.Write(sb.ToString());
Response.End();
}
示例5: btnExportar_Command
protected void btnExportar_Command(object sender, CommandEventArgs e)
{
if (e.CommandName == "Exportar")
{
if (GridView1.Rows.Count > 0 && GridView1.Visible == true ){
//try{
lblMsj.Text = "";
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
HtmlTextWriter htw = new HtmlTextWriter(sw);
Page page = new Page();
HtmlForm form = new HtmlForm();
GridView1.EnableViewState = false;
// Deshabilitar la validación de eventos, sólo asp.net 2
page.EnableEventValidation = false;
// Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD.
page.DesignerInitialize();
page.Controls.Add(form);
form.Controls.Add(GridView1);
page.RenderControl(htw);
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment;filename=Evaluaciones.xls");
Response.Charset = "UTF-8";
Response.ContentEncoding = Encoding.Default;
Response.Write(sb.ToString());
Response.End();
}
else
{
//lblMsj.Text = "la tabla no contiene datos para exportar...";
}
//}
//catch (Exception ex)
//{
// EventLogger ev = new EventLogger();
// ev.Save("Seguimiento, export excel ", ex);
//}
}
}
示例6: Button3_Click
protected void Button3_Click(object sender, EventArgs e)
{
string xn = xnDDL.SelectedValue;
string xq = xqDDL.SelectedValue;
string z = zDDL.SelectedValue;
string sysid = sysDDL.SelectedValue;
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["syxkConn"].ConnectionString);
string sql = "select symc,jsxm,syxingq,syks,id from v_ywcsyjhb where syxn='" + xn + "' and syxq=" + xq + " and syz=" + z + " and sysid= " + sysid + "order by syxn,syxq,syz,syxingq,syks";
SqlDataAdapter ada = new SqlDataAdapter(sql, conn);
DataTable dt = new DataTable();
ada.Fill(dt);
Table1.Caption = xn + "年——" + xqDDL.SelectedItem.Text + "——" + zDDL.SelectedItem.Text + "——" + sysDDL.SelectedItem.Text + "实验安排表";
for (int i = 1; i <= 7; i++)
{
for (int j = 1; j <= 7; j++)
{
TableCell tc = Table1.FindControl("TableCell" + i.ToString() + j.ToString()) as TableCell;
if (tc == null)
{
}
else
{
//tc.Text = @"<a href=eadm_syjh_bg.aspx?&ap=1&syxingq=" + j.ToString() + @"&syks=" + i.ToString() + @">安排实验</a>";
tc.Text = " ";
}
}
}
for (int i = 0; i < dt.Rows.Count; i++)
{
string symc = dt.Rows[i]["symc"].ToString();
string jsxm = dt.Rows[i]["jsxm"].ToString();
string syjhid = dt.Rows[i]["id"].ToString();
int syxingq = Convert.ToInt32(dt.Rows[i]["syxingq"]);
int syks = Convert.ToInt32(dt.Rows[i]["syks"]);
TableCell tc = Table1.FindControl("TableCell" + syks.ToString() + syxingq.ToString()) as TableCell;
if (tc == null)
{
}
else
{
//tc.Text = symc + "(" + jsxm + @")<br><a href=eadm_syjh_bg.aspx?ap=2&syjhid=" + syjhid + @">取消实验</a>";
tc.Text = symc + "(" + jsxm + ")";
}
}
string fileName = "export.xls";
System.Text.StringBuilder sb = new System.Text.StringBuilder();
System.IO.StringWriter sw = new System.IO.StringWriter(sb);
HtmlTextWriter htw = new HtmlTextWriter(sw);
Page page = new Page();
HtmlForm form = new HtmlForm();
// Deshabilitar la validación de eventos, sólo asp.net 2
page.EnableEventValidation = false;
// Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD.
page.DesignerInitialize();
page.Controls.Add(form);
form.Controls.Add(Table1);
page.RenderControl(htw);
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
Response.Charset = "UTF-8";
Response.ContentEncoding = System.Text.Encoding.Default;
Response.Write(sb.ToString());
Response.End();
}
示例7: exportToExcel
private void exportToExcel(string nameReport, GridView fuente)
{
HttpResponse response = Response;
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
Page pageToRender = new Page();
HtmlForm form = new HtmlForm();
form.Controls.Add(fuente);
pageToRender.Controls.Add(form);
response.Clear();
response.Buffer = true;
response.ContentType = "application/vnd.ms-excel";
response.AddHeader("Content-Disposition", "attachment;filename=" + nameReport);
response.Charset = "UTF-8";
response.ContentEncoding = Encoding.Default;
pageToRender.RenderControl(htw);
response.Write(sw.ToString());
response.End();
}
示例8: SavePageASHtml
//public bool CreateWebPage()
//{
// HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://opi.yahoo.com/online");
// request.Timeout = 9 * 1000; // set request timeout = 9 second. if yahoo api failed to respond in 9 second request would get timed out.
// request.Method = "Post"; // we will post the data using post method
// string postData = "u=" + TextBox1.Text + "&m=s&t=8";
// // data to be posted using HttpWebrequest post method
// // we will post parameter u , m and t
// // Convert this string into stream of bytes
// byte[] arrPostDAta = System.Text.Encoding.GetEncoding(1252).GetBytes(postData);
// // set request content length = post data length
// request.ContentLength = arrPostDAta.Length;
// System.IO.Stream strmPostData = request.GetRequestStream();
// // get request stream
// // write post data to stream of request
// strmPostData.Write(arrPostDAta, 0, arrPostDAta.Length);
// strmPostData.Close();
// // upload post data and Get Response from server
// HttpWebResponse response = (HttpWebResponse)request.GetResponse();
// StreamReader reader = new StreamReader(response.GetResponseStream());
// Label1.Text = reader.ReadToEnd();
// reader.Close();
// response.Close();
//}
public void SavePageASHtml(string location, Page pge)
{
StringWriter stringWriter = new StringWriter();
HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);
pge.RenderControl(htmlWriter);
htmlWriter.Flush();
FileStream fileStream = new FileStream(location, FileMode.Create);
string siteString = stringWriter.ToString();
byte[] byteArray = Encoding.UTF8.GetBytes(siteString);
fileStream.Write(byteArray, 0, byteArray.Length);
fileStream.Close();
//Response.End();
//Response.Redirect("~/PriceList.aspx");
}
示例9: ImprimirControle
/// <summary>
/// Imprime um controle de uma página, com script
/// <summary>
public static void ImprimirControle(Control ctl, string script)
{
try
{
if (ctl != null)
{
StringWriter stringWrite = new StringWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
if (ctl is WebControl)
{
Unit w = new Unit(100, UnitType.Percentage);
((WebControl)ctl).Width = w;
}
Page pg = new Page();
pg.EnableEventValidation = false;
if (script != string.Empty)
{
pg.ClientScript.RegisterStartupScript(pg.GetType(), string.Empty, script);
}
HtmlForm frm = new HtmlForm();
pg.Controls.Add(frm);
frm.Attributes.Add("runat", "server");
frm.Controls.Add(ctl);
pg.DesignerInitialize();
pg.RenderControl(htmlWrite);
string strHTML = stringWrite.ToString();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentEncoding = Encoding.UTF8;
HttpContext.Current.Response.Write(strHTML);
string print = "<script type=\"text/javascript\" language=\"javascript\">window.print();</script>";
HttpContext.Current.Response.Write(print);
HttpContext.Current.Response.End();
HttpContext.Current.Response.Flush();
}
}
catch { }
}
示例10: exportarExcel
protected void exportarExcel(GridView nomGV)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
System.IO.StringWriter sw = new System.IO.StringWriter(sb);
System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);
Page page = new Page();
HtmlForm form = new HtmlForm();
nomGV.EnableViewState = false;
page.EnableEventValidation = false;
page.DesignerInitialize();
page.Controls.Add(form);
form.Controls.Add(nomGV);
page.RenderControl(htw);
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment;filename=RegistroWeb.xls");
Response.Charset = "UTF-8";
Response.Write(sb.ToString());
Response.End();
}
示例11: ReporteHorizontal
//.........这里部分代码省略.........
htw.Write("<td width='150' align='center'>DIA 09</td>");
htw.Write("<td width='150' align='center'>DIA 10</td>");
htw.Write("<td width='150' align='center'>DIA 11</td>");
htw.Write("<td width='150' align='center'>DIA 12</td>");
htw.Write("<td width='150' align='center'>DIA 13</td>");
htw.Write("<td width='150' align='center'>DIA 14</td>");
htw.Write("<td width='150' align='center'>DIA 15</td>");
htw.Write("<td width='150' align='center'>DIA 16</td>");
htw.Write("<td width='150' align='center'>DIA 17</td>");
htw.Write("<td width='150' align='center'>DIA 18</td>");
htw.Write("<td width='150' align='center'>DIA 19</td>");
htw.Write("<td width='150' align='center'>DIA 20</td>");
htw.Write("<td width='150' align='center'>DIA 21</td>");
htw.Write("<td width='150' align='center'>DIA 22</td>");
htw.Write("<td width='150' align='center'>DIA 23</td>");
htw.Write("<td width='150' align='center'>DIA 24</td>");
htw.Write("<td width='150' align='center'>DIA 25</td>");
htw.Write("<td width='150' align='center'>DIA 26</td>");
htw.Write("<td width='150' align='center'>DIA 27</td>");
htw.Write("<td width='150' align='center'>DIA 28</td>");
htw.Write("<td width='150' align='center'>DIA 29</td>");
htw.Write("<td width='150' align='center'>DIA 30</td>");
htw.Write("<td width='150' align='center'>DIA 31</td>");
htw.Write("</tr>");
foreach (DataRow dr2 in dt2.Rows)
{
htw.Write("<tr>");
htw.Write("<td align='center' class='textmode'>" + dr2["DDNNI"].ToString().Trim() + "</td>");
htw.Write("<td align='center' class='textmode'>" + dr2["NOMBS"].ToString().Trim() + "</td>");
htw.Write("<td align='center' class='textmode'>" + dr2["D1"].ToString().Trim() + "</td>");
htw.Write("<td align='center' class='textmode'>" + dr2["D2"].ToString().Trim() + "</td>");
htw.Write("<td align='center' class='textmode'>" + dr2["D3"].ToString().Trim() + "</td>");
htw.Write("<td align='center' class='textmode'>" + dr2["D4"].ToString().Trim() + "</td>");
htw.Write("<td align='center' class='textmode'>" + dr2["D5"].ToString().Trim() + "</td>");
htw.Write("<td align='center' class='textmode'>" + dr2["D6"].ToString().Trim() + "</td>");
htw.Write("<td align='center' class='textmode'>" + dr2["D7"].ToString().Trim() + "</td>");
htw.Write("<td align='center' class='textmode'>" + dr2["D8"].ToString().Trim() + "</td>");
htw.Write("<td align='center' class='textmode'>" + dr2["D9"].ToString().Trim() + "</td>");
htw.Write("<td align='center' class='textmode'>" + dr2["D10"].ToString().Trim() + "</td>");
htw.Write("<td align='center' class='textmode'>" + dr2["D11"].ToString().Trim() + "</td>");
htw.Write("<td align='center' class='textmode'>" + dr2["D12"].ToString().Trim() + "</td>");
htw.Write("<td align='center' class='textmode'>" + dr2["D13"].ToString().Trim() + "</td>");
htw.Write("<td align='center' class='textmode'>" + dr2["D14"].ToString().Trim() + "</td>");
htw.Write("<td align='center' class='textmode'>" + dr2["D15"].ToString().Trim() + "</td>");
htw.Write("<td align='center' class='textmode'>" + dr2["D16"].ToString().Trim() + "</td>");
htw.Write("<td align='center' class='textmode'>" + dr2["D17"].ToString().Trim() + "</td>");
htw.Write("<td align='center' class='textmode'>" + dr2["D18"].ToString().Trim() + "</td>");
htw.Write("<td align='center' class='textmode'>" + dr2["D19"].ToString().Trim() + "</td>");
htw.Write("<td align='center' class='textmode'>" + dr2["D20"].ToString().Trim() + "</td>");
htw.Write("<td align='center' class='textmode'>" + dr2["D21"].ToString().Trim() + "</td>");
htw.Write("<td align='center' class='textmode'>" + dr2["D22"].ToString().Trim() + "</td>");
htw.Write("<td align='center' class='textmode'>" + dr2["D23"].ToString().Trim() + "</td>");
htw.Write("<td align='center' class='textmode'>" + dr2["D24"].ToString().Trim() + "</td>");
htw.Write("<td align='center' class='textmode'>" + dr2["D25"].ToString().Trim() + "</td>");
htw.Write("<td align='center' class='textmode'>" + dr2["D26"].ToString().Trim() + "</td>");
htw.Write("<td align='center' class='textmode'>" + dr2["D27"].ToString().Trim() + "</td>");
htw.Write("<td align='center' class='textmode'>" + dr2["D28"].ToString().Trim() + "</td>");
htw.Write("<td align='center' class='textmode'>" + dr2["D29"].ToString().Trim() + "</td>");
htw.Write("<td align='center' class='textmode'>" + dr2["D30"].ToString().Trim() + "</td>");
htw.Write("<td align='center' class='textmode'>" + dr2["D31"].ToString().Trim() + "</td>");
htw.Write("</tr>");
}
htw.Write("</table>");
htw.Write("<table>");
htw.Write("<tr>");
htw.Write("<td></td>");
htw.Write("</tr>");
htw.Write("<tr>");
htw.Write("<td></td>");
htw.Write("</tr>");
htw.Write("</table>");
}
}
page.RenderControl(htw);
string style = @"<style> .textmode { mso-number-format:\@; } .intmode { mso-number-format:'0'; } .decmode { mso-number-format:'\#\,\#\#0\.00'; }</style>";
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment;filename=Lista_Asistencias.xls");
Response.Charset = "UTF-8";
Response.ContentEncoding = Encoding.Default;
// Escribe estilo
Response.Write(style);
Response.Write(sb.ToString());
Response.End();
//HttpContext.Current.ApplicationInstance.CompleteRequest();
}
catch (Exception ex)
{
this.ClientMessage(ex.Message);
}
}
示例12: btnExcel2_Click
//.........这里部分代码省略.........
BE.flvis = false;
//******** Exportando a Excel ***********
try
{
DataTable dt = new DataTable();
dt = BL.GetAll(Session["ssEmpresaID"].ToString(), BE).Tables[0];
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
HtmlTextWriter htw = new HtmlTextWriter(sw);
Page page = new Page();
HtmlForm form = new HtmlForm();
//Se Deshabilita la validación de eventos, sólo asp.net 2
page.EnableEventValidation = false;
//Se Realiza las inicializaciones de la instancia de la clase Page
page.DesignerInitialize();
//*** GENERAR REPORTE
htw.Write("<table width='10000' border='1' cellpadding='0' cellspacing='0' style='font:Tahoma; font-size:12px;'>");
htw.Write("<tr>");
htw.Write("<td width='79'> </td>");
htw.Write("<td width='205'> </td>");
htw.Write("<td colspan='6' rowspan='2' align='center' style='font-size:18px;'><strong>LISTADO DE ASISTENCIA</strong></td>");
htw.Write("<td width='72'> </td>");
htw.Write("<td width='76'> </td>");
htw.Write("</tr>");
htw.Write("<tr>");
htw.Write("<td> </td>");
htw.Write("<td> </td>");
htw.Write("<td> </td>");
htw.Write("<td> </td>");
htw.Write("</tr>");
htw.Write("<tr>");
htw.Write("<td colspan='10'><strong> DEL:</strong> [" + FECH1.Text.ToString() + "] <strong>AL:</strong> [" + FECH2.Text.ToString() + "]</td>");
htw.Write("</tr>");
htw.Write("<tr>");
htw.Write("<td colspan='10'> </td>");
htw.Write("</tr>");
htw.Write("<tr style='color: #FFFFFF; font-weight: bold; background-color:#006699;'>");
htw.Write("<td width='200' align='center'>FECHA</td>");
htw.Write("<td width='150' align='center'>AREA</td>");
htw.Write("<td width='200' align='center'>DNI</td>");
htw.Write("<td width='250' align='center'>TRABAJADOR</td>");
htw.Write("<td width='100' align='center'>DIA</td>");
htw.Write("<td width='150' align='center'>MARCA</td>");
htw.Write("<td width='150' align='center'>MIN/TRA</td>");
htw.Write("<td width='150' align='center'>GLOSA</td>");
htw.Write("<td width='150' align='center'>RANGO</td>");
htw.Write("</tr>");
foreach (DataRow dr in dt.Rows)
{
htw.Write("<tr>");
htw.Write("<td align='center'>" + dr["FECHA"].ToString().Trim() + "</td>");
htw.Write("<td align='center' class='textmode'>" + dr["NBCC2"].ToString().Trim() + "</td>");
htw.Write("<td align='center' class='textmode'>" + dr["DDNNI"].ToString().Trim() + "</td>");
htw.Write("<td class='textmode'>" + dr["NOMBS"].ToString().Trim() + "</td>");
htw.Write("<td align='center' class='textmode'>" + dr["NBDIA"].ToString().Trim() + "</td>");
htw.Write("<td align='center' class='textmode'>" + dr["MARCA"].ToString().Trim() + "</td>");
htw.Write("<td align='center'>" + dr["HorasTrabajadas"].ToString().Trim() + "</td>");
htw.Write("<td align='center' class='textmode'>" + dr["GLOSA"].ToString().Trim() + "</td>");
htw.Write("<td align='center' class='textmode'>" + dr["RANGO"].ToString().Trim() + "</td>");
htw.Write("</tr>");
}
htw.Write("</table>");
htw.Write("<table><tr><td></td></tr></table>");
page.RenderControl(htw);
string style = @"<style> .textmode { mso-number-format:\@; } .intmode { mso-number-format:'0'; } .decmode { mso-number-format:'\#\,\#\#0\.00'; }</style>";
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment;filename=ListaAsistencia.xls");
Response.Charset = "UTF-8";
Response.ContentEncoding = Encoding.Default;
// Escribe estilo
Response.Write(style);
Response.Write(sb.ToString());
Response.End();
//HttpContext.Current.ApplicationInstance.CompleteRequest();
}
catch (Exception ex)
{
this.ClientMessage(ex.Message);
}
}
示例13: Btn_Exportar_XLS_Click
protected void Btn_Exportar_XLS_Click(object sender, EventArgs e)
{
// - Exporta Gridview a Excel, crea planilla completa aunque el Gridview tenga páginas
if (GridView1.Rows.Count > 0 && GridView1.Visible == true)
{
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
HtmlTextWriter htw = new HtmlTextWriter(sw);
Page page = new Page();
HtmlForm form = new HtmlForm();
string filename = "Listado.xls";
GridView1.EnableViewState = false;
GridView1.AllowPaging = false;
GridView1.AllowSorting = false;
GridView1.DataBind();
GridView1.HeaderStyle.Reset();
// Recorre todas las filas
for (int i = 0; i < GridView1.Rows.Count; i++)
{
GridViewRow row = GridView1.Rows[i];
// Aplica estilo a cada celda, diferencia por el numero de columna si debe aplicar formato
// texto o numero
for (int j = 0; j < row.Cells.Count; j++)
{
if (j == 3 || j == 6)
{
row.Cells[j].Attributes.Add("class", "num1"); // formato numero
}
else
{
row.Cells[j].Attributes.Add("class", "textmode"); // formato texto
}
}
}
// Define estilo para formato texto y numérico
string style = @"";
page.EnableEventValidation = false;
page.DesignerInitialize();
page.Controls.Add(form);
form.Controls.Add(GridView1);
page.RenderControl(htw);
Response.Clear();
Response.Buffer = true;
Response.ContentType = "text/plain";
Response.AddHeader("Content-Disposition", "attachment;filename=" + filename);
Response.Charset = "UTF-8";
Response.ContentEncoding = Encoding.Default;
// Escribe estilo
Response.Write(style);
// Agrega título en primera celda
string Titulo = " LISTADO DE ASISTENCIA ";
HttpContext.Current.Response.Write(Titulo);
Response.Write(sb.ToString());
Response.End();
}
}