1

Is there a way to create this using HtmlTextWriter? I am trying to create a method to create html dynamically server-side

<fieldset class='ui-grid-a' data-theme='c'>

Here is a start on the code I am not sure how to create the "data-theme" attribute because there is no enum offered for that..

// Initialize StringWriter instance.
StringWriter stringWriter = new StringWriter();

// Put HtmlTextWriter in using block because it needs to call Dispose.
using (HtmlTextWriter writer = new HtmlTextWriter(stringWriter))
{
    foreach (string employee in myList)
    {
        writer.RenderBeginTag(HtmlTextWriterTag.Fieldset);
        writer.AddAttribute(HtmlTextWriterAttribute.Class, "ui-grid-a");
        writer.AddAttribute(HtmlTextWriterAttribute., "ui-grid-a");
    }
}
Ria
  • 10,237
  • 3
  • 33
  • 60
Nick LaMarca
  • 8,076
  • 31
  • 93
  • 152
  • You mean you want to create server-side tag in ASP.NET ?! – Kamran Amini Sep 10 '12 at 22:34
  • Remember that if you create a custom html "attribute" (this is what you are referring to in your question, not a html tag) you could create invalid XHTML. Check this out: http://stackoverflow.com/questions/1735230/can-i-add-custom-attribute-to-html-tag – Hanlet Escaño Sep 10 '12 at 22:53

1 Answers1

4

Regarding the comment: Here is a start on the code I am not sure how to create the "data-theme" attribute because there is no enum offered for that..

Do not use the overload that only takes the enum and instead the overload that accepts two string values: http://msdn.microsoft.com/en-us/library/985bhaz6.aspx

e.g.

writer.AddAttribute("data-theme", "c");
Nicodemeus
  • 4,005
  • 20
  • 23