本文整理汇总了C#中System.Web.UI.HtmlTextWriter.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlTextWriter.ToString方法的具体用法?C# HtmlTextWriter.ToString怎么用?C# HtmlTextWriter.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.UI.HtmlTextWriter
的用法示例。
在下文中一共展示了HtmlTextWriter.ToString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExportExcel
public ActionResult ExportExcel()
{
string xmlData = HttpContext.Server.MapPath("~/App_Data/GridColumn.xml");//Path of the xml script
DataSet ds = new DataSet();//Using dataset to read xml file
ds.ReadXml(xmlData);
DataTable dtRecords = ds.Tables[0];// Data Table
int recordsCount = dtRecords.Rows.Count;
var grid = new GridView();
grid.DataSource = dtRecords;
grid.DataBind();
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment; filename=MyExcelFile.xls");
Response.ContentType = "application/ms-excel";
Response.Charset = "";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
DownloadFileActionResult download = new DownloadFileActionResult(grid, "Cars.xls");
download.ExecuteResult(this.ControllerContext);
grid.RenderControl(htw);
Response.Output.Write(htw.ToString());
Response.Flush();
Response.End();
return new EmptyResult();
}
示例2: IgnoresChildren
public void IgnoresChildren ()
{
Button b = new Button ();
b.Controls.Add (new LiteralControl ("hola"));
Assert.AreEqual (1, b.Controls.Count, "controls");
StringWriter sw = new StringWriter ();
HtmlTextWriter tw = new HtmlTextWriter (sw);
b.RenderControl (tw);
string str = tw.ToString ();
Assert.AreEqual (-1, str.IndexOf ("hola"), "hola");
}
示例3: GetControl
/// <summary>
/// Renders The Given Control Into The String Output
/// </summary>
/// <param name="control">The WebControl To Be Converted</param>
/// <returns>The Rendered Result Of The Given Control</returns>
///
private static string GetControl(WebControl control)
{
StringWriter stringWriter = new StringWriter();
HtmlTextWriter textWriter = new HtmlTextWriter(stringWriter);
control.RenderControl(textWriter);
textWriter.Flush();
return textWriter.ToString();
}