1

I have this html code

<table id="rounded" runat=server style="position:relative;left:-45px;"  >
    <thead>
        <tr>
            <th scope="col" class="rounded-company">status</th>
        <th scope="col" class="rounded-q1">date</th>

            <th scope="col" class="rounded-q1">price</th>
             <th scope="col" class="rounded-q1">quantity</th>
              <th scope="col" class="rounded-q1">option1</th>
               <th scope="col" class="rounded-q1">option2</th>
                <th scope="col" class="rounded-q1">paync</th>
                 <th scope="col" class="rounded-q1">product_id</th>

                   <th scope="col" class="rounded-q1">sell number</th>
                   <th scope="col" class="rounded-q4"> name</th>


        </tr>
    </thead>
        <tfoot>
        <tr>
            <td colspan="9" class="rounded-foot-left" dir=rtl ><em></em></td>
            <td class="rounded-foot-right">&nbsp;</td>
        </tr>
    </tfoot>

</table>

In serer side I want to add this string to the table rows

rows="<tr><td>" & reader4.GetValue(9) & "</td>" & "<td>" & reader4.GetValue(8) & "</td>" & "<td>" & reader4.GetValue(7) & "</td>" & _
                         "<td>" & reader4.GetValue(3) & "</td>" & "<td>" & tempoption & "</td>" & "<td>" & tempoption2 & "</td>" & _
                          "<td>" & reader4.GetValue(6) & "</td>" & "<td>" & reader4.GetValue(2) & "</td>" & "<td>" & reader4.GetValue(1) & "</td>" & "<td>" & reader4.GetValue(0) & "</td>" & "</tr>"

In javascript it very sipmle

  $("#rounded").html( $("#rounded").html()+str);

but asp.net doesn't support InnerHTML for tables

What is the right approach for this task?

3 Answers 3

2

Don't add markup to a serverside table - add HtmlTableRows in the code behind.

C#:

var tr = new HtmlTableRow();
tr.Cells.Add(new HtmlTableCell(reader4.GetValue(9));
tr.Cells.Add(new HtmlTableCell(reader4.GetValue(8));
...

rounded.Rows.Add(tr);

VB.NET:

Dim tr as HtmlTableRow = New HtmlTableRow()
tr.Cells.Add(New HtmlTableCell(reader4.GetValue(9))
tr.Cells.Add(New HtmlTableCell(reader4.GetValue(8))
...

rounded.Rows.Add(tr)
Sign up to request clarification or add additional context in comments.

2 Comments

Hi Oded ,thanks for the replay-I need code in server side (vb) and your code is javascript
@baaroz - No, my code is C#. And you never specified VB.NET as the language - next time, please tag correctly. Answer updated with VB.NET example.
0

You can have a table as a server object

  1. // Generate rows and cells.

        int numrows = 3;
        int numcells = 2;
        for (int j = 0; j < numrows; j++)
        {          
            TableRow r = new TableRow();
            for (int i = 0; i < numcells; i++) {
                TableCell c = new TableCell();
                c.Controls.Add(new LiteralControl("row " 
                    + j.ToString() + ", cell " + i.ToString()));
                r.Cells.Add(c);
            }
            Table1.Rows.Add(r);
        }
    

Comments

0

You are right I checked it. But you still can use Rows.Add method for your table. I tried and it works:

HtmlTableRow a = new HtmlTableRow();            

        HtmlTableCell cell = new HtmlTableCell();
        cell.InnerHtml = "test";
        a.Cells.Add(cell);

        HtmlTableCell cell2 = new HtmlTableCell();
        cell2.InnerHtml = "test";
        a.Cells.Add(cell2);
        HtmlTableCell cell3 = new HtmlTableCell();
        cell3.InnerHtml = "test";
        a.Cells.Add(cell3);
        HtmlTableCell cell4 = new HtmlTableCell();
        cell4.InnerHtml = "test";
        a.Cells.Add(cell4);
        HtmlTableCell cell5 = new HtmlTableCell();
        cell5.InnerHtml = "test";
        a.Cells.Add(cell5);
        HtmlTableCell cell6 = new HtmlTableCell();
        cell6.InnerHtml = "test";
        a.Cells.Add(cell6);
        HtmlTableCell cell7 = new HtmlTableCell();
        cell7.InnerHtml = "test";
        a.Cells.Add(cell7);
        HtmlTableCell cell8 = new HtmlTableCell();
        cell8.InnerHtml = "test";
        a.Cells.Add(cell8);
        HtmlTableCell cell9 = new HtmlTableCell();
        cell9.InnerHtml = "test";
        a.Cells.Add(cell9);
        HtmlTableCell cell10 = new HtmlTableCell();
        cell10.InnerHtml = "test";
        a.Cells.Add(cell10);


        ((HtmlTable)rounded).Rows.Add(a);  

where rounded is your table.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.