本文整理汇总了C#中System.Web.UI.HtmlControls.HtmlForm.RenderControl方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlForm.RenderControl方法的具体用法?C# HtmlForm.RenderControl怎么用?C# HtmlForm.RenderControl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.UI.HtmlControls.HtmlForm
的用法示例。
在下文中一共展示了HtmlForm.RenderControl方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: xlsport
public static void xlsport(GridView grd, string _fnm, Page p)
{
grd.Visible = true;
gridstrip(grd);
grd.DataBind();
HtmlForm form = new HtmlForm();
string attachment = "attachment; filename=" + _fnm + csclass.ranfn() + ".xls";
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.AddHeader("content-disposition", attachment);
HttpContext.Current.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
p.EnableViewState = false;
HttpContext.Current.Response.Charset = string.Empty;
System.IO.StringWriter stw = new System.IO.StringWriter();
HtmlTextWriter htextw = new HtmlTextWriter(stw);
form.Controls.Add(grd);
p.Controls.Add(form);
form.RenderControl(htextw);
HttpContext.Current.Response.Write(stw.ToString());
HttpContext.Current.Response.End();
}
示例2: btnexporttoexc_Click
protected void btnexporttoexc_Click(object sender, EventArgs e)
{
try
{
string sysDates = DateTime.Now.ToString("dd/MM/yyyy");
string FileName = sysDates;
string strFileName = FileName + ".xls";
btnSearch_Click(sender, e);
//GridViewExportUtil.ExportExcell(strFileName, Grdiworkreg);
string attachment = "attachment; filename=" + strFileName + " ";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
HtmlForm frm = new HtmlForm();
GridView2.AllowPaging = false;
GridView2.Parent.Controls.Add(frm);
frm.Attributes["runat"] = "server";
frm.Controls.Add(GridView2);
frm.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('" + ex.Message + "');", true);
}
}
示例3: btnExportErrors_Clicked
protected void btnExportErrors_Clicked(object sender, EventArgs e)
{
Response.Clear();
Response.AddHeader("content-disposition", "attachment; filename=ImportErrorList.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.xls";
StringWriter stringWrite = new StringWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
HtmlForm newForm = new HtmlForm();
this.Controls.Add(newForm);
newForm.Controls.Add(gvErrorDetails);
newForm.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
this.Dispose();
}
示例4: btnExcel_Click
protected void btnExcel_Click(object sender, EventArgs e)
{
HtmlForm form = new HtmlForm();
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition",
"attachment;filename=GridViewExport.xls");
Response.ContentType = "application/ms-excel";
Response.Charset = "utf-8";
Response.ContentEncoding = System.Text.Encoding.UTF8;
HttpContext.Current.Response.Write("<font style='font-size:10.0pt; font-family:Times New Roman;'>");
HttpContext.Current.Response.Write("<BR><BR><BR>");
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
form.Controls.Add(grDSSum);
this.Controls.Add(form);
form.RenderControl(hw);
Response.Write(sw.ToString());
Response.End();
}
示例5: btXuatExcel_Click
protected void btXuatExcel_Click(object sender, EventArgs e)
{
HtmlForm form = new HtmlForm();
string fileName = string.Format("BaoCao_SuCo_NgungGiam_{0}", DateTime.Now.ToString("MMyyyy_ddhhmm"));
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment; filename=" + fileName + ".xls");
Response.ContentType = "application/ms-excel";
Response.Charset = string.Empty;
Response.ContentEncoding = Encoding.Unicode;
Response.BinaryWrite(Encoding.Unicode.GetPreamble());
StringWriter strWri = new StringWriter();
HtmlTextWriter txtWri = new HtmlTextWriter(strWri);
Load_Data();
form.Controls.Add(gvSuCo);
this.Controls.Add(form);
form.RenderControl(txtWri);
Response.Write(strWri.ToString());
Response.End();
}
示例6: Export
public static void Export(WebControl grid, Page page, string Filename, bool treatAsText, params int[] textColumns)
{
if ((treatAsText))
{
try
{
foreach (GridViewRow row in ((GridView)grid).Rows)
if (textColumns == null || textColumns.Length == 0)
{
foreach (TableCell cell in row.Cells) cell.Attributes.Add("class", "text");
}
else
{
foreach (int i in textColumns) row.Cells[i].Attributes.Add("class", "text");
}
}
catch { }
}
HttpResponse response = HttpContext.Current.Response;
response.Clear();
response.Buffer = true;
response.AddHeader("content-disposition", string.Concat("attachment;filename=", Filename));
response.ContentEncoding = Encoding.Unicode;
response.BinaryWrite(Encoding.Unicode.GetPreamble());
response.Cache.SetCacheability(HttpCacheability.NoCache);
response.ContentType = "application/vnd.ms-excel";
page.EnableViewState = false;
HtmlForm frm = new HtmlForm();
page.Controls.Add(frm);
frm.Controls.Add(grid);
StringWriter stringWrite = new StringWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
frm.RenderControl(htmlWrite);
response.Write(@"<style>.text { mso-number-format:\@; }</style>");
response.Write(stringWrite.ToString());
response.Flush();
response.End();
}
示例7: doPdfButton_Click
protected void doPdfButton_Click(object sender, EventArgs e)
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=Export.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
HtmlForm frm = new HtmlForm();
panel1.Parent.Controls.Add(frm);
frm.Attributes["runat"] = "server";
frm.Controls.Add(panel1);
frm.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
}
示例8: btLuu_Click
protected void btLuu_Click(object sender, EventArgs e)
{
try
{
HtmlForm form = new HtmlForm();
string fileName = string.Format("CORE_{0}", DateTime.Now.ToString("yyMMdd_hhmmss"));
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment; filename=" + fileName + ".xls");
Response.ContentType = "application/ms-excel";
Response.Charset = string.Empty;
Response.ContentEncoding = Encoding.Unicode;
Response.BinaryWrite(Encoding.Unicode.GetPreamble());
StringWriter strWri = new StringWriter();
HtmlTextWriter txtWri = new HtmlTextWriter(strWri);
form.Controls.Add(gvCore);
this.Controls.Add(form);
form.RenderControl(txtWri);
Response.Write(strWri.ToString());
Response.End();
}
catch { }
}
示例9: btnExport_Click
protected void btnExport_Click(object sender, EventArgs e)
{
HtmlForm form = new HtmlForm();
Response.Clear();
Response.Buffer = true;
string filename="GridViewExport_"+DateTime.Now.ToString()+".xls";
Response.AddHeader("content-disposition","attachment;filename="+filename);
Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
gvParent.AllowPaging = false;
//gvParent.DataBind();
form.Controls.Add(gvParent);
this.Controls.Add(form);
form.RenderControl(hw);
//style to format numbers to string
string style = @"<style> .textmode { mso-number-format:\@; } </style>";
Response.Write(style);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
}
示例10: pdfport
public static void pdfport(GridView gv, string fileName, int lans, Page p)
{
gv.Visible = true;
gridstrip(gv);
gv.DataBind();
string attachment = "attachment; filename=" + fileName + csclass.ranfn() + ".pdf";
HttpContext.Current.Response.ContentType = "application/pdf";
HttpContext.Current.Response.AddHeader("content-disposition", attachment);
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
HtmlForm frm = new HtmlForm();
gv.Parent.Controls.Add(frm);
frm.Attributes["runat"] = "server";
frm.Controls.Add(gv);
frm.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A3, 10f, 10f, 10f, 0f);
if (lans == 1)
{
pdfDoc.SetPageSize(iTextSharp.text.PageSize.A3.Rotate());
}
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, HttpContext.Current.Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
HttpContext.Current.Response.Write(pdfDoc);
HttpContext.Current.Response.End();
}
示例11: GenerateExcelFiles
public static void GenerateExcelFiles(string filename, GridView gv)
{
string attachment = "attachment; filename=" + filename + ".xls";
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.AddHeader("content-disposition", attachment);
HttpContext.Current.Response.ContentType = "application/ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
// Create a form to contain the grid
HtmlForm frm = new HtmlForm();
gv.Parent.Controls.Add(frm);
frm.Attributes["runat"] = "server";
frm.Controls.Add(gv);
frm.RenderControl(htw);
//GridView1.RenderControl(htw);
HttpContext.Current.Response.Write(sw.ToString());
HttpContext.Current.Response.End();
}
示例12: Save
//protected static string ReadCss()
//{
// string res;
// string fileName = string.Format("table.css");
// string path = Path.Combine(HttpRuntime.AppDomainAppPath, @"App_Themes\Default\" + fileName);
// using (StreamReader s = new StreamReader(path))
// {
// res = s.ReadToEnd();
// }
// return res;
//}
public static bool Save(WebControl grid, string path)
{
try
{
using (StreamWriter s = new StreamWriter(path, false, Encoding.Unicode))
{
Page page = new Page();
page.EnableViewState = false;
HtmlForm frm = new HtmlForm();
frm.Attributes["runat"] = "server";
page.Controls.Add(frm);
frm.Controls.Add(grid);
StringWriter stringWrite = new StringWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
frm.RenderControl(htmlWrite);
string start = @"<style>.text { mso-number-format:\@; }</style>";
s.Write(start);
s.Write(stringWrite.ToString());
}
return true;
}
catch
{
throw;
}
}
示例13: btnWord_Click
protected void btnWord_Click(object sender, EventArgs e)
{
HtmlForm form = new HtmlForm();
//Response.Clear();
//Response.Buffer = true;
Response.AddHeader("content-disposition",
"attachment;filename=GridViewExport.doc");
Response.ContentType = "application/ms-word";
Response.Charset = "UTF-8";
Response.ContentEncoding = System.Text.Encoding.UTF8;
//set font
HttpContext.Current.Response.Write("<font style='font-size:10.0pt; font-family:Calibri;'>");
HttpContext.Current.Response.Write("<BR><BR><BR>");
//Response.BinaryWrite(System.Text.Encoding.UTF8.GetPreamble());
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
// Bỏ phân trang - Nếu chỉ muỗn Export Trang hiện hành thì chọn =true
form.Controls.Add(grDSSum);
this.Controls.Add(form);
form.RenderControl(hw);
//grDSSum.RenderControl(hw);
//Thay đổi Style
hw.WriteLine("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">");
Response.Write(sw.ToString());
//Response.Flush();
Response.End();
}