Forum guidelines
AuthorQuestion
C# code for Tabular list
Posted By Abhijit P on 14 Jul 2009

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:
 
 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);
 }

Abhijit
AuthorReply
Re: C# code for Tabular list
Posted By Niradhip Chakraborty on 14 Jul 2009  

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.

Regards,
Niradhip(James Hetfield)
MCP,MVC,MVP(Mindcracker)
--------------------------------------------------------------------------------------
Please remember to click “Do you like this answer” on the post that helps you.
Re: C# code for Tabular list
Posted By Abhijit P on 15 Jul 2009  
Thanks! I think this will work for me.
Abhijit

SPONSORED BY

Custom Software Development
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.