DataList Not Listed in ControlCollection

R

rn5a

An ASP.NET Form has different server controls like Panels, Labels,
TextBoxes, HiddenFields etc. The Form has a DataList as well. This is
how the DataList looks:

<form runat="server">
<asp:DataList ID="dlUsers" runat="server">
<HeaderTemplate>
<table border=2>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>E-Mail</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# Container.DataItem("FirstName") %></td>
<td><%# Container.DataItem("LastName") %></td>
<td><%# Container.DataItem("EMail") %></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:DataList>
</form>

Note that the Form houses other web server controls as well like
Panels, Labels, HiddenFields etc. Now when I do

<script runat="server">
Sub Page_Load(obj As Object, ea As EventArgs)
Dim i As Integer
For i = 0 To Form.Controls.Count - 1
Response.Write(Form.Controls.Item(i).ToString & "<br>")
Next
End Sub
</script>

Surprisingly, the DataList doesn't get listed as one of the Controls in
the ControlsCollection though the other controls like Panels, Labels
etc. do get listed. What's causing this abnormality?

The same happens when I iterate through the Page's ControlCollection
i.e. the DataList doesn't get listed as one of the controls though the
other server controls do!

Note that I am not adding the DataList dynamically.
 
M

Mark Fitzpatrick

The best way to see the controls is to look at the trace output. It will
essentially walk down through the control list. I believe that DataLists,
Repeaters and the like are treated differently and essentially show up as
Literal content instead of an actual DataList showing up. Enable tracing and
look through the control tree on the trace and you should be able to spot it
in the control list.
 

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