BlaDrzz BlaDrzz - 8 days ago 6
Vb.net Question

ASP.NET & VB.net html ID adding

I want to make a big table with 100 cells and I did that by using the "insert table" option but when you do that the td's have no ID's to them so I can't talk with them in code. Now I'm just making a small part of what will later be a table with 1000's of cells.

I was thinking of something like:

Dim i As Integer
For i = 0 To 100
(What do I put here?).Attributes.Add(ClientID, "td" & i.ToString)
Next


My HTML looks like:

<table class="style1">
<tr>
<td id="td1" runat="server">
&nbsp;</td>
<td id="td2" runat="server">
&nbsp;</td>
<td>
&nbsp;</td>


but then I have 100 td's not just 3.

Any suggestions?

Answer

Try something like this. You have to make the table accessible to the server side.

<table class="style1" runat="server" id="theTable">
</table>


Dim row as New TableRow()
theTable.Rows.Add(row)

Dim i As Integer
For i = 0 To 100
  Dim cell as New TableCell()
  cell.Attributes.Add(ClientID, "td" & i.ToString)
  row.Cells.Add(cell)
Next