?
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,178 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
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.…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month12 days, 19 hours left to enroll

777 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