Position a HTML Table using C# code

Posted on 2009-04-23
Last Modified: 2013-12-17
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";







Open in new window

Question by:aspgeek
    LVL 8

    Expert Comment

    by:Faheem Shaikh
    Try this link:
    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.Attributes.Add("class", "tableItems");

    Open in new window

    LVL 7

    Accepted Solution

    You have to use absolute positioning in style.

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

    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
    This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now