Editing Writing HTML to a String
Jump to:
navigation
,
search
If you want to be able to populate a Panel or otherwise generate HTML to a string, it's complex, but straightforward. Bring in the following references to your class and project: Imports System.Web.UI Imports System.Text Get your data from your dataset: Dim Content_DT As ClixMKP_DataSet.ContentDataTable = Content_TA.GetDataForSiteAbbrev(SiteAbbrev) Now declare a StringBuilder, a StringWriter, and an HTMLTextWriter, each one based on the previous item: Dim SB As New Text.StringBuilder Dim SW As IO.TextWriter = New IO.StringWriter(SB) Dim HTML As New System.Web.UI.HtmlTextWriter(SW) Start the rendering process: HTML.BeginRender() Now loop through the records in your data table, one record at a time. In this case, I'm generating three paragraphs. Note that in order to generate attributes and style entries, you have to "add" those '''before''' the actual begin tag. For Each Content_Rec As ClixMKP_DataSet.ContentRow In Content_DT.Rows HTML.AddStyleAttribute("color", "Blue") HTML.AddStyleAttribute("font-weight", "Bolder") HTML.AddStyleAttribute("font-size", "Larger") HTML.RenderBeginTag(HtmlTextWriterTag.P) HTML.Write(Content_Rec.ContentHeader) HTML.RenderEndTag() ' HTML.AddStyleAttribute("padding", "20px") HTML.RenderBeginTag(HtmlTextWriterTag.P) HTML.Write(Content_Rec.ContentHTML) HTML.RenderEndTag() ' HTML.AddStyleAttribute("text-decoration", "italic") HTML.RenderBeginTag(HtmlTextWriterTag.P) HTML.AddAttribute("href", Content_Rec.ContentLinkURL) HTML.AddAttribute("target", "_blank") HTML.RenderBeginTag(HtmlTextWriterTag.A) HTML.Write("Click for more...") HTML.RenderEndTag() HTML.RenderEndTag() ' Next Now finish the rendering: HTML.EndRender() And finally, generate the text: Dim ReturnHTML As String = "" ReturnHTML = SB.ToString
|
Editing help
Personal tools
Create account
Log in
Namespaces
Page
Discussion
Variants
Views
Read
Edit
View history
Actions
Search
Navigation
Main page
Community portal
Current events
Recent changes
Random page
Help
Toolbox
What links here
Related changes
Special pages