views:

300

answers:

0

I don't get this issue. If I have a ListView and it is databound to a datatable with 1 item in the listview, why does the Item Count = 0 when I try to access a control in the ListView using the ListView.Item[0].FindControl(".....") method?

Here is sample code from the msdn page on the ListView Control. Imagine the SqlDataSource1 returns 1 row from the database so it gets inserted into the ItemTemplate, I would think that Item[0] would correspond to that Item, but it does not?

<asp:ListView runat="server" ID="ListView1" 
    DataSourceID="SqlDataSource1">
    <LayoutTemplate>
    <table runat="server" id="table1" runat="server" >
    <tr runat="server" id="itemPlaceholder" ></tr>
    </table>
    </LayoutTemplate>
    <ItemTemplate>
    <tr runat="server>
    <td runat="server">
    <asp:Label ID="NameLabel" runat="server" 
      Text='<%#Eval("Name") %>' />
    </td>
    </tr>
    </ItemTemplate>
    </asp:ListView>