Simple Nested repeater

Hi,

I'm trying to create a simple nested repeater following the tutorial on ASP.NET> Nested Data Web Controls.
But I'm having problems. While executing I get an error System.NullReferenceException: Object reference not set to an instance of an object.

, In debugmode I see that ObjectDataSource2 = Nothing.

Can somebody give me advise how to take things further?
here is my code:
Protected Sub Repeater1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles Repeater1.ItemDataBound
        If e.Item.ItemType = ListItemType.AlternatingItem OrElse e.Item.ItemType = ListItemType.Item Then
            Dim Rol As planning.aspnet_Roles_GetAllRolesRow = CType(CType(e.Item.DataItem, System.Data.DataRowView).Row, planning.aspnet_Roles_GetAllRolesRow)
            ObjectDataSource2.SelectParameters("ApplicationName").DefaultValue = "MyApplication"
            ObjectDataSource2.SelectParameters("RoleName").DefaultValue = Rol.RoleName.ToString
 
        End If
    End Sub
 
 
And in the actual page:
 
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="ObjectDataSource1">    
    <ItemTemplate>  
    <br /><br />
    <asp:Label runat="server" Text='<%# Eval("RoleName") %>'></asp:Label>    
        <asp:Repeater ID="Repeater2" runat="server" DataSourceID="ObjectDataSource2">
        <ItemTemplate >
            <asp:Label runat="server" Text='<%# Eval("UserName") %>'></asp:Label><br />
        </ItemTemplate>
        </asp:Repeater>
    </ItemTemplate>  
        </asp:Repeater>
  <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
        OldValuesParameterFormatString="original_{0}" SelectMethod="GetData" 
        TypeName="planningTableAdapters.aspnet_Roles_GetAllRolesTableAdapter">
        <SelectParameters>
            <asp:Parameter DefaultValue="MyApplication" Name="ApplicationName" 
                Type="String" />
        </SelectParameters>
    </asp:ObjectDataSource>
 
 
    <asp:ObjectDataSource ID="ObjectDataSource2" runat="server" 
        OldValuesParameterFormatString="original_{0}" SelectMethod="GetData" 
        TypeName="planningTableAdapters.aspnet_UsersInRoles_GetUsersInRolesTableAdapter">
        <SelectParameters>
            <asp:Parameter DefaultValue="MyApplication" Name="ApplicationName" 
                Type="String" />
            <asp:Parameter DefaultValue="" Name="RoleName" Type="String" />
        </SelectParameters>
    </asp:ObjectDataSource>

Open in new window

jean4spaAsked:
Who is Participating?
 
David RobitailleAnalyst ProgrammerCommented:
move your ObjectDataSource2 inside the Repeater ID="Repeater1"
You will also have to "find" it using e.Item.FindControl("ObjectDataSource2")

asp:Repeater ID="Repeater1" runat="server" DataSourceID="ObjectDataSource1">    
    <ItemTemplate>  
    <br /><br />
    <asp:Label runat="server" Text='<%# Eval("RoleName") %>'></asp:Label>    
        <asp:Repeater ID="Repeater2" runat="server" DataSourceID="ObjectDataSource2">
        <ItemTemplate >
            <asp:Label runat="server" Text='<%# Eval("UserName") %>'></asp:Label><br />
        </ItemTemplate>
        </asp:Repeater>
        <asp:ObjectDataSource ID="ObjectDataSource2" runat="server" 
        OldValuesParameterFormatString="original_{0}" SelectMethod="GetData" 
        TypeName="planningTableAdapters.aspnet_UsersInRoles_GetUsersInRolesTableAdapter">
        <SelectParameters>
            <asp:Parameter DefaultValue="MyApplication" Name="ApplicationName" 
                Type="String" />
            <asp:Parameter DefaultValue="" Name="RoleName" Type="String" />
        </SelectParameters>
    </asp:ObjectDataSource>
 
    </ItemTemplate>  
        </asp:Repeater>
  <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
        OldValuesParameterFormatString="original_{0}" SelectMethod="GetData" 
        TypeName="planningTableAdapters.aspnet_Roles_GetAllRolesTableAdapter">
        <SelectParameters>
            <asp:Parameter DefaultValue="MyApplication" Name="ApplicationName" 
                Type="String" />
        </SelectParameters>
    </asp:ObjectDataSource>
 
 
    

Open in new window

0
 
jean4spaAuthor Commented:
Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.