0

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?

1
  • You dont want 1000's of cells. The page will never render in time or the user will just ignore it anyways. Commented Feb 25, 2014 at 22:24

2 Answers 2

1

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
Sign up to request clarification or add additional context in comments.

2 Comments

@StingyJack Had to make a few changes because it gave me an error when adding the row telling me that it had to be a htmlrow and same thing whith the cell but works great thanks again!
Yeah, was doing from memory and Craig's link. Glad it worked for you.
0

I agree with StingyJack's comment. However, if you REALLY do need that many cells, have you looked into the Table control (available in the Visual Studio Toolbox)?

I just +1 StingyJack's answer...this is what I was preparing as well...

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.