Position a HTML Table using C# code

Hi ,
I am dynamically creating a table "TABLE2" . How do i cnage the positioing of teh HTML table and its cells . By default the values are being printed on the left most corner of the web page.

Please help

if (recordSet3.Tables[0].Rows.Count > 0)
        {
            int i =0;
            HtmlTable Table2 = new HtmlTable();
 
            for (i = 0; i < recordSet3.Tables[0].Rows.Count; i++)
            {
            Label celltext = new Label();
            HtmlTableRow r2 = new HtmlTableRow();
            HtmlTableCell c2 = new HtmlTableCell();
            celltext.Text = recordSet3.Tables[0].Rows[i]["EMPNO"].ToString();
            //r2.Align = "Right";
            c2.Controls.Add(celltext);
            r2.Cells.Add(c2);
            Table2.Rows.Add(r2);
            }
            form1.Controls.Add(Table2);
 
        }

Open in new window

aspgeekAsked:
Who is Participating?
 
csharppConnect With a Mentor Commented:
You have to use absolute positioning in style.


Table2.Style["position"] = "absolute";
Table2.Style["left"] = "400px";
Table2.Style["top"] = "200px";

Open in new window

0
 
Faheem ShaikhCommented:
Try this link: http://sanjeewa070.blogspot.com/2008/08/create-html-table-dynamically-by-c-code.html
Check the piece of code below, you can add the attributes as in the example.

HtmlTableCell htmlForumItemEmptyCell = new HtmlTableCell();
htmlForumItemEmptyCell.InnerHtml = "";
htmlForumItemEmptyCell.Attributes.Add("width", "100");
htmlForumItemEmptyCell.Attributes.Add("valign", "top");
htmlForumItemEmptyCell.Controls.Add(link);
htmlForumItemEmptyCell.Attributes.Add("class", "tableItems");
htmlForumItemRow.Cells.Add(htmlForumItemEmptyCell);

Open in new window

0
All Courses

From novice to tech pro — start learning today.