Click to See Complete Forum and Search --> : [RESOLVED] FindControl Input Text?


birre
04-24-2007, 05:49 AM
Hi,

In my code, I dynamically make a table to display a year calendar. This is the code how the table is build up :


Private Sub opvullenYearTable(ByVal year As Integer)
lblJaar2.Text = year.ToString()
Dim i As Integer
Dim j As Integer
For i = 1 To 12
Dim r As TableRow = New TableRow()
For j = 0 To DateTime.DaysInMonth(year, i)
Dim c As TableCell = New TableCell()
If (j = 0) Then
Dim l As New Label
l.Width = "70"
l.Text = "Maand" + i.ToString()
c.Controls.Add(l)
Else
Dim l As New TextBox
If (i < 10) Then
l.ID = "ID" + year.ToString() + "0" + i.ToString()
Else
l.ID = "ID" + year.ToString() + i.ToString()
End If
If (j < 10) Then
l.ID = "ID" + l.ID + "0" + j.ToString()
Else
l.ID = "ID" + l.ID + j.ToString()
End If
l.Width = "14"
l.CssClass = "TEXTLABEL"
c.Controls.Add(l)
End If
r.Cells.Add(c)
Next
tblCalendar.Rows.Add(r)
Next
End Sub


Now this is a piece of code of how the html shows up:


<table id="ctl00_ContentPlaceHolder1_tblCalendar" cellspacing="0" rules="all" border="1" style="border-collapse:collapse;">
<tr id="ctl00_ContentPlaceHolder1_TableRow1">
</tr>
<tr>
<td>
<span style="display:inline-block;width:70px;">Maand1</span>
</td>
<td>
<input name="ctl00$ContentPlaceHolder1$IDID20070101" type="text" id="ctl00_ContentPlaceHolder1_IDID20070101" class="TEXTLABEL" style="width:14px;" />
</td>
<td>
<input name="ctl00$ContentPlaceHolder1$IDID20070102" type="text" id="ctl00_ContentPlaceHolder1_IDID20070102" class="TEXTLABEL" style="width:14px;" />
</td>
<td>
<input name="ctl00$ContentPlaceHolder1$IDID20070103" type="text" id="ctl00_ContentPlaceHolder1_IDID20070103" class="TEXTLABEL" style="width:14px;" />
</td>
<td>
<input name="ctl00$ContentPlaceHolder1$IDID20070104" type="text" id="ctl00_ContentPlaceHolder1_IDID20070104" class="TEXTLABEL" style="width:14px;" />
</td>
<td><input name="ctl00$ContentPlaceHolder1$IDID20070105" type="text" id="ctl00_ContentPlaceHolder1_IDID20070105" class="TEXTLABEL" style="width:14px;" />
</td>
<td>
<input name="ctl00$ContentPlaceHolder1$IDID20070106" type="text" id="ctl00_ContentPlaceHolder1_IDID20070106" class="TEXTLABEL" style="width:14px;" />
</td>
</tr>
.....


so good, so far, but now here's the problem :
I'm trying to fill up the controls with text from my dataset. This is how i'm trying to do this :


Dim b As Control
Dim i As Integer
For i = 0 To DS.Tables(0).Rows.Count - 1
b = Page.FindControl("ctl00_ContentPlaceHolder1_IDID" + Format(DS.Tables(0).Rows(i).Item(0), "yyyyMMdd"))
b.Text = DS.Tables(0).Rows(i).Item(0).ToString()
Next


the problem is : he never finds the control, so i can't change the text on it!?
Is there a proper way to make this work, or something i do wrong to retrieve the control?

I really hope someone can help me out here!

thank you

birre
04-24-2007, 08:11 AM
Resolved : didn't realise the master page was giving me troubles :rolleyes:

sheltonmega
05-30-2007, 09:43 AM
Thanks!

birre
05-31-2007, 05:25 AM
the solution is quite easy :


Dim mpContentPlaceHolder As ContentPlaceHolder
mpContentPlaceHolder = CType(Master.FindControl("contentplaceholderid"), ContentPlaceHolder)
Dim b as TableCell = CType(mpContentPlaceHolder.FindControl("controlid",TableCell)
b.Text = "text"
b.Style("text-align") = "center"