Thursday, 10 October 2013

How to Write dynamicly HTML code using C#

Now I am suggesting for dynamically HTML Code generation  in ASP.Net using C#,

Whenever we have need for creating dynamically menu or any others type controls  we can use this technique.

public static string GetHTML()
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.Append("<div>");
            sb.Append("<ul>");
            for (int i = 0; i <= 10; i++)
            {
                sb.Append("<li>" + i + " </li>");
            }
            sb.Append("</ul>");
                sb.Append("</div>");

return sb.Tostring();

        }

Here function GetHTML will return a string which has contain HTML code,

You can also this :
<div id="divHTML" runat="server"/>

divHTML.innerHTML=GetHTML();


Basically this concept is very rich for generating report in asp.net because Gridview is heavy wait control then html.

0 comments:

Post a Comment