1

I have some ASP.NET code that dynamically generates rows and cells for a Table control on the page.

I have specifically set the ID of each cell, but I am having trouble getting FindControl to actually find them.

Here's the code that I use to create the cells:

tbc = New TableCell
tbr.Cells.Add(tbc)
tbc.ID = String.Format("tc_{0}-{1}-{2}", curStartDate.Day, curStartDate.Month, curStartDate.Year)

Just below that, I try to find the control with the following:

Dim ctlName As String = String.Format("tc_{0}-{1}-{2}", curStartDate.Day, curStartDate.Month, curStartDate.Year)
Dim ctl As Control = tblAllocations.FindControl(ctlName)

I have tried swapping the line that declares the ID, with the line that adds the cell to the Cells collection of the TableRow, and that makes it work. But throughout my application, I have the statements in the order as above, and they works fine (FindControl can find the control with the correct ID).

Is there something obvious I am missing?

4

1 回答 1

1

当您说“略低于此”时,您是否已将 tbr 添加到 tblAllocations.Rows 中?如果不是那将是找不到它的原因。

于 2009-04-21T11:37:59.000 回答