Find controls

A

Anonymous

Hello,

in my init I am adding some controls into a
placeholder. The complete procedure looks like this:

Dim iLoop As Integer = 0
Dim table As New Table
table.BackColor = System.Drawing.Color.Gainsboro
table.CellPadding = 2
table.CellSpacing = 0

Dim tr As New TableRow

For iLoop = 0 To dsHeaderLinks.Tables(0).Rows
().Count() - 1
Dim td As New TableCell
td.ID = dsHeaderLinks.Tables(0).Rows(iLoop)
("ID")

If iLoop = 0 Then
td.Attributes.Add("class", "SelectedCell")
Else
td.Attributes.Add
("class", "UnSelectedCell")
End If

Dim link As New HyperLink
link.Font.Bold = True
link.Text = "  " &
dsHeaderLinks.Tables(0).Rows(iLoop)("LinkText")
& "  "
link.NavigateUrl = "/intranet" &
dsHeaderLinks.Tables(0).Rows(iLoop)("Link") & "?Index=" &
dsHeaderLinks.Tables(0).Rows(iLoop)("ID")
link.ToolTip = IIf(IsDBNull
(dsHeaderLinks.Tables(0).Rows(iLoop)("LinkTooltip")), "",
dsHeaderLinks.Tables(0).Rows(iLoop)("LinkTooltip"))

td.Controls.Add(link)
tr.Controls.Add(td)
Next

table.Controls.Add(tr)
HeaderMenuHolder.Controls.Add(table)

Now in my pageload I need to get access to the Tablecells,
so that I can set a new class for them. What would be the
best way to do that?

Thanks
 
K

Karl Seguin

The best way would be to hold on to a referene to them...it'll be faster and
cleaner.

private cells as new ArrayList()

OnInit
.....
tr.Controls.Add(td)
cells.Add(td)
....
end oninit

OnLoad
for each cell as HtmlTableCell in cells
cell....
next
end onload

Karl
 
S

Stefano

Hi,

why are you using Controls collection to add cells in rows?
You should use:
tr.Cells.Add(td)
instead of:
tr.Controls.Add(td)

Then, you can declare the htmltable variable at Class-Level

Public Class MyControl
Dim table As New Table
...

In this way you can access it from both OnInit and OnLoad. Then you can
iterates its cells using Rows and Cells collections, for example:
table.Rows(rowindex).Cells(cellindex)

HTH

Bye

Stefano
 
A

anonymous

Thanks

-----Original Message-----
Hi,

why are you using Controls collection to add cells in rows?
You should use:
tr.Cells.Add(td)
instead of:
tr.Controls.Add(td)

Then, you can declare the htmltable variable at Class- Level

Public Class MyControl
Dim table As New Table
...

In this way you can access it from both OnInit and OnLoad. Then you can
iterates its cells using Rows and Cells collections, for example:
table.Rows(rowindex).Cells(cellindex)

HTH

Bye

Stefano

"Anonymous" <[email protected]> ha scritto nel messaggio



.
 

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