I'm using SharePoint 2010. I've created a web visual web part that queries a list and returns a set of results. What I would like to do now is to format and display the output using HTML code.
In my VisualWebPart.ascx.cs
module I have created a method to create some html output using HtmlTextWriter
based on the results received (an example of the code is shown below):
private void renderField(SPListItem item, HtmlTextWriter writer, String className, String fieldName, String label) {
if (!string.IsNullOrEmpty(item[fieldName].ToString()))
{
writer.AddAttribute(HtmlTextWriterAttribute.Class, className);
writer.RenderBeginTag(HtmlTextWriterTag.Div);
writer.AddAttribute(HtmlTextWriterAttribute.Class, "some-label");
writer.RenderBeginTag(HtmlTextWriterTag.Div);
writer.Write(label);
writer.RenderEndTag(); // close some-label div
writer.AddAttribute(HtmlTextWriterAttribute.Class, "some-value");
writer.RenderBeginTag(HtmlTextWriterTag.Div);
writer.Write(item[fieldName].ToString());
writer.RenderEndTag(); // close some-value div
writer.RenderEndTag(); // close className div
}
}
My question is what is the best way to get this HTML to display on the screen? I've seen examples of placing this text in a label control but seems wrong to me. What is the proper approach to use?