Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

vb.net How can I add rows to an existing html table in code behind..

Posted on 2011-02-14
6
Medium Priority
?
1,259 Views
Last Modified: 2012-06-27
Hi experts..

I have a template that I load that is comprised of a simple html table structure..

structure is similar to below..

<table id="MainForm">
   <tr>
      <th>
         Column1
      </th>
      <th>
         Column2
      </th>
      <th>
         Column3
      </th>
   </tr>
   .
   .
   .
</table>

In the dotted section I want to prgramatically insert <tr> and <td> elements..

Reason is that I am building an email template on the fly that will contain a variable number of rows retrieved from a database..

The table structure is fairly basic and static (column headings etc..), but the nbumber of rows returns will be varialble..

Can someone help in pointing me to the right way to achieve this please?

Thanks in advance..

D
   
0
Comment
Question by:jcm4101
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 6

Expert Comment

by:kswathi
ID: 34886151
0
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 500 total points
ID: 34886152
set the runat=server property to table tag like this and id

<table id="MainForm" runat= "server">

then in code behind

 //Instantiate Row Object and Cell Object

       

        HtmlTableRow htRow = new HtmlTableRow();

        HtmlTableCell htCell = new HtmlTableCell();        

 

        //Add Text to cell and add Cell to Row

 

        htCell.InnerText = "This is Implementation of HTML Control";

        htRow.Cells.Add(htCell);

        MainForm.Rows.Add(htRow);

 

        //Add Second Row in a Table

       

        htRow = new HtmlTableRow();

        htCell = new HtmlTableCell();

 

        TextBox txttext = new TextBox();

        txttext.Visible = true;

        txttext.Text = "Inside Cell";

       

        htCell.Controls.Add(txttext);

        htRow.Cells.Add(htCell);

        MainForm.Rows.Add(htRow);



0
 

Assisted Solution

by:spooky07
spooky07 earned 500 total points
ID: 34886163
You have to create a  a Label Control or PlaceHolder Control in your HTML

string htmlTable = "<table><tr><td>" + yourData + </td></tr></table>;

YourLabel.Text = htmlTable;
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Assisted Solution

by:soujanya_g
soujanya_g earned 500 total points
ID: 34886169

Hi
Just look this code
protected void Page_Load(object sender, EventArgs e)
{
 
        //Instantiate Row Object and Cell Object
       
        HtmlTableRow htRow = new HtmlTableRow();
        HtmlTableCell htCell = new HtmlTableCell();      
 
        //Set the sytle of a table
       
        table1.BgColor = "#FCDDFE";
        table1.Align = "left";
        table1.Border = 1;
        table1.Attributes["Style"] = "font-family:Verdana;font-size:11px;font-style:italic;";
 
        //Add Text to cell and add Cell to Row
 
        htCell.InnerText = "This is Implementation of HTML Control";
        htRow.Cells.Add(htCell);
        table1.Rows.Add(htRow);
 
        //Add Second Row in a Table
       
        htRow = new HtmlTableRow();
        htCell = new HtmlTableCell();
 
        TextBox txttext = new TextBox();
        txttext.Visible = true;
        txttext.Text = "Inside Cell";
       
        htCell.Controls.Add(txttext);
        htRow.Cells.Add(htCell);
        table1.Rows.Add(htRow);
 
}
0
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 500 total points
ID: 34886313
One way this could be done is that you store the header only in the template like below

<table id="MainForm">
   <tr>
      <th>
         Column1
      </th>
      <th>
         Column2
      </th>
      <th>
         Column3
      </th>
   </tr>


Note the missing </table> tag. Now you can just append text to the template and then at the end, append the </table></body></html> nodes when finished.



If there is more than </table></body></html> at the end, you can store it in a separate file and append that file at the end.
0
 

Author Closing Comment

by:jcm4101
ID: 34939858
Hi all..
Thanx for the responses..
To be honest, all solutions presented would have worked, so I split the points equally..
I ended up using a solution that used placeholdes in a standard HTML form, then replacing these placeholders with valid HTML in code behind, that I built on the fly after pulling the data from the DB..(Just like PHP)
Once again, thanx for the solutions..All very helpful.

D
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

618 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