0

I have an HTML table with runat="server" in asp.net.

I want to add row to the table On click event of a button or some thing like that, my table is like:

<table id="table1" runat="server"></table>

I tried table1.InnerHtml = "<tr></td>Test</td></tr>";

but it does not work and I get this exception:

System.NotSupportedException: 'HtmlTable' does not support the InnerHtml property.

How can I achieve this?

1
  • This maybe your answer in MSDN Commented Oct 8, 2012 at 9:46

3 Answers 3

2

You need to add a row to the table, and a cell to this row:

var row = new HtmlTableRow();
var cell = new HtmlTableCell() { InnerText = "Test" };
row.Cells.Add(cell);
table1.Rows.Add(row);
Sign up to request clarification or add additional context in comments.

Comments

2

You need to add the rows and cells explicitly:

Untested:

var newRow = new HtmlTableRow();
var newCell = new HtmlTableCell();

newCell.InnerText = "Test";

newRow.Cells.Add(newCell);

table1.Rows.Add(newRow);

Comments

1

I Execute the above code in vb.net , and it creates a new row with text that i input in textbox, when i click button. but problem is that it only create one row, and alter the first row with new input on second click. I need

<table id="Mytable" runat="server">
    <tr><td>Row Data 1.....!</td></tr>  //New row on 1st click
    <tr><td>Row Data 2.....!</td></tr>  //New row on 2nd click
    <tr><td>Row Data 3.....!</td></tr>  //New row on 3rd click
</table>

a New Row every time when i click button. How we can do this?

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.