Site icon Sibeesh Passion

Create HTML DIV Dynamically

Introduction

This blog explains how we can generate a HTML Div dynamically. For this you must be aware of basic HTML, CSS.

Steps

Create a static string variable html:
[html]
public static string html = "";
[/html]
Add <%=html%> in the aspx file inside of the from tag.

Add a function like this:
[csharp]
private string LoadDragEventsByUserID(string userId)
{
try
{
DataSet ds = Fetch dataset from your server
html = string.Empty;
for (int i = 0; i <= ds.Tables[0].Rows.Count – 1; i++)
{
html += "<div id=’" + ds.Tables[0].Rows[i]["Your Unique ID"].ToString() + "</div>";
}

return html;
}
catch
{
return null;
}
}
[/csharp]

Please note that your dataset rows will be contained different rows and columns, please change it according to your need. And also create css styles your own. If you need any help regarding style, feel free to ask me.

Exit mobile version