Skip to content

C# code for Tabular list

Abhijit P

Asked Jul 14, 2009, 2:44 AM EDT2 answers
Share
LinkedInX
I need to convert a list into tabular format. I tried using normal HTML code but didnt work. I need 2 cols. in the table. This is a aspx.cs file.
Please help me with this as i am a newbie.
The list code is given below:
C#
 
 private void AddCategoryToMenu(string title)
 {
  HtmlAnchor a = new HtmlAnchor();
  a.InnerHtml = Server.HtmlEncode(" " + title) + "<BR>";
  a.HRef = "#" + Utils.RemoveIllegalCharacters(title);
  a.Attributes.Add("rel", "directory");
  HtmlGenericControl li = new HtmlGenericControl("img align=middle src=images/icons/" + title );
  li.Controls.Add(a);
  ulMenu.Controls.Add(li);
 }

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Niradhip Chakraborty
    0

    You can create it using javascript:

     

    Here is my html table code:

     

    <tr>

                                                                                <td style="padding-left: 15px">

                                                                                    <div style="overflow-y: auto; height: 85px; width: 280px;" style="padding-left: 05px">

                                                                                        <asp:Table ID="tblBoothPersonal" CellPadding="0" CellSpacing="0" runat="server" onclick="SelectBoothPersonal(event);">

                                                                                        </asp:Table>

                                                                                    </div>

                                                                                </td>

                                                                            </tr>

     

    //Javascript code.

     

     

    function EnterBoothpersonal()

    {

       var tbl = document.getElementById('tblBoothPersonal');

                    var mytablebody = document.createElement("TBODY");

                    var hidfirstname;

                    var row = document.createElement("TR");

                    row.setAttribute('id', document.getElementById("txtBoothFirstName").value)

     

    //here I am creating first column 

     var NewCell = document.createElement("TD");

                          var Fname = document.getElementById("txtBoothFirstName").value;

                    var textNode = document.createTextNode(Fname);

                    NewCell.appendChild(textNode);

                    NewCell.setAttribute('width','130px');

                    row.appendChild(NewCell);

    //here I am creating second column

    var NewCell = document.createElement("TD");

                    var CallSign = document.getElementById("txtBoothCallSign").value;

                    var textNode = document.createTextNode(CallSign)

                    NewCell.appendChild(textNode);

                    NewCell.setAttribute('width','75px');

                    row.appendChild(NewCell);

     

     

                    mytablebody.appendChild(row);

                    tbl.appendChild(mytablebody);

     

    }

    Note: I have used txtBoothFirstName and txtBoothCallSign to create the table.You can use your list element and traverse through a loop to get next row.

    0
  • 0
    Thanks! I think this will work for me.
    0