Add HTML Rows in a html table

T

TR

Hi! I have a webpage with a htmltable and a button in it.
When I push the button, I want to insert a new row with a cell in the
table. With my code I can add a row the first time a push the button,
but the second time nothing happens when I push the buttom. Why is it
like this? and how to make this possible? I have this code under my
buttons click event in my behind code class:

Dim r As New HtmlTableRow
r.Visible = True

Dim c As New HtmlTableCell
c.Visible = True
c.Attributes.Add("class", "Inmatning")
r.Cells.Add(c)

Table2.Rows.Insert(Table2.Rows.Count, r)

How to do if I want a row to be added EVERY time i push the button,
not only the first time?
 
B

BluDog

Hi! I have a webpage with a htmltable and a button in it.
When I push the button, I want to insert a new row with a cell in the
table. With my code I can add a row the first time a push the button,
but the second time nothing happens when I push the buttom. Why is it
like this? and how to make this possible? I have this code under my
buttons click event in my behind code class:

Dim r As New HtmlTableRow
r.Visible = True

Dim c As New HtmlTableCell
c.Visible = True
c.Attributes.Add("class", "Inmatning")
r.Cells.Add(c)

Table2.Rows.Insert(Table2.Rows.Count, r)

How to do if I want a row to be added EVERY time i push the button,
not only the first time?

When you push the button a postback takes place, returning the page to
it's original state, you must add any rows that were subsequently
added dynamically in the OnLoad method of the page.

You could have a look at this custom control that will better maintain
the ViewState of your dynamic table:

http://www.denisbauer.com/ASPNETControls/DynamicControlsPlaceholder.aspx

Hope this helps

Blu.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top