[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Simple Nested repeater

Posted on 2009-02-09
2
Medium Priority
?
397 Views
Last Modified: 2012-08-14
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

0
Comment
Question by:jean4spa
2 Comments
 
LVL 18

Accepted Solution

by:
David Robitaille earned 500 total points
ID: 23590394
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
 

Author Closing Comment

by:jean4spa
ID: 31544501
Thanks.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question