Hazel Mahmud

Hazel Mahmud

  • 1.4k
  • 315
  • 70k

positioning dynamic created div

Nov 14 2015 9:17 PM
i have created a div using stringbuilder which result as below picture
 

 
 
below are my coding
 
protected void Page_Load(object sender, EventArgs e)
{
int divID = 0;

using (SqlConnection stud = studPortConn.GetStudPortCon())
{
stud.Open();

da.SelectCommand = new SqlCommand("SELECT moduleID,moduleDesc FROM Module WHERE systemID = '3'", stud);
SqlDataReader sc = da.SelectCommand.ExecuteReader();

if (sc.HasRows)
{
while (sc.Read())
{

divID++;

var modID = sc["moduleID"].ToString();

StringBuilder stringBuilder = new StringBuilder();

stringBuilder.Append("<div style='background-color:red;padding-top:20px;padding-bottom:20px;padding-left:1em;width:500px;height:auto;position:relative; id='" + divID + ">");

stringBuilder.AppendFormat("<div style='background-color:#b9b8b8;height:40px;padding-left:1em;padding-top:1em; width:350px;'>" + sc["moduleDesc"].ToString() + "</div>");

stringBuilder.Append("<div style='background-color:#f1efef;padding-top:20px;padding-bottom:20px;padding-left:1em;width:350px;height:auto;'>");
stringBuilder.Append("<div style='background-color:#f1efef;padding-top:5px;padding-left:1px;height:100%;width:320px;border:solid;border-color:#b9b8b8;border-size:0.5px;'>");
using (SqlConnection stud1 = studPortConn.GetStudPortCon())
{
stud1.Open();

da.SelectCommand = new SqlCommand("SELECT moduleID,menuDesc,menuPath FROM Menu WHERE moduleID='" + modID + "'", stud1);
SqlDataReader sc1 = da.SelectCommand.ExecuteReader();

if (sc1.HasRows)
{

while (sc1.Read())
{
stringBuilder.AppendFormat("<div style='background-color:#f1efef;padding-left:0.5em;height:25px;width:300px; '>" + "<a style='color:blue;' href=" + sc1["menuPath"].ToString() + ">" + sc1["menuDesc"].ToString() + "</a>" + "</div>");
}
}
stringBuilder.Append("</div>");
stringBuilder.Append("</div>");
stringBuilder.Append("</div>");


if (stringBuilder.Length > 0)
{
divtajukText.Controls.Add(new Literal { Text = stringBuilder.ToString() });

divtajukText.Visible = true;
}

divtajukText.Controls.Add(new LiteralControl("<br />"));
}
}
}
}
 
how do i make the third and so on created div, position in second column and third column adding in my coding?.. please anyone help me..TQ so much.
 

Answers (3)