468,244 Members | 2,047 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,244 developers. It's quick & easy.

repeater inside a repeater problem.

Hello everyone,
I'm fairly new at .Net and I have a repeater inside a repeater problem. I will attach my code to this message but basically what I am able to tell when I run my page it tells me that my second repeater has the following error, System.NullReferenceException: Object reference not set to an instance of an object.

When I put a watch on I can see my second repeater is not being created because it is equal to "Nothing". I can tell that this is not creating the object properly but I don't understand why. Before I paste my code I want to explain the process I am trying to do so the code is more understandable. The first repeater on my page pulls the duties that are available from a table using a stored procedure, the second repeater process is supposed to create the sub duties that are linked to a categorey of duties. The code gets all the way to building the bind child sub-duties process to the part where it is supposed to populate the repeater but it tells me the error and the repeater is "Nothing".
Notice that the line Protected WithEvents drptrDIVConstRollsChild As System.Web.UI.WebControls.Repeater
exists in my backend and that the repeater is called the same inside the other repeater.
My code is as follows and thanks in advance for your help.
Mike

--------ASP Page for front end--------

<%@ Import Namespace="System.Data" %>
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="PhoneListInfo.aspx.vb" Inherits="D4ConstWeb.PhoneListInfo" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>Phone List Info</title>
<META http-equiv="Content-Type" content="text/html; charset=windows-1252">
<LINK href="./style/DIVStyle.css" type="text/css" rel="stylesheet">
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body>
<table cellpadding=0 cellspacing=0>
<asp:Repeater id="drptrDIVConstRollsParent" runat="server">
<ItemTemplate>
<tr class="Header">
<td><%# DataBinder.Eval(container.dataitem, "Duty") %></td>
<td>
Primary
</td>
<td>
Secondary
</td>
</TR>
<asp:Repeater ID="drptrDIVConstRollsChild" Runat="server" DataSource='<%# Container.DataItem.Row.GetChildRows("myrelation") %>'>
<ItemTemplate>
<tr Class="OddItem">
<td>&nbsp;<%# DataBinder.Eval(container.dataitem, "SubDutyType") %></td>
<td><a href="mailto:<%# DataBinder.Eval(container.dataitem, "PrimeEmail") %>"><%# DataBinder.Eval(container.dataitem, "Prime") %></a></td>
<td><a href="mailto:<%# DataBinder.Eval(container.dataitem, "SecondEmail") %>"><%# DataBinder.Eval(container.dataitem, "Secondary") %></a><%# DataBinder.Eval(container.dataitem, "Seperator") %><a href="mailto:<%# DataBinder.Eval(container.dataitem, "SubSecondEmail") %>"><%# DataBinder.Eval(container.dataitem, "SubSecondary") %></a></td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr Class="EvenItem">
<td>&nbsp;<%# DataBinder.Eval(container.dataitem, "SubDutyType") %></td>
<td><a href="mailto:<%# DataBinder.Eval(container.dataitem, "PrimeEmail") %>"><%# DataBinder.Eval(container.dataitem, "Prime") %></a></td>
<td><a href="mailto:<%# DataBinder.Eval(container.dataitem, "SecondEmail") %>"><%# DataBinder.Eval(container.dataitem, "Secondary") %></a><%# DataBinder.Eval(container.dataitem, "Seperator") %><a href="mailto:<%# DataBinder.Eval(container.dataitem, "SubSecondEmail") %>"><%# DataBinder.Eval(container.dataitem, "SubSecondary") %></a></td>
</tr>
</AlternatingItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
</table>
</body>
</HTML>


------ASP Page for Back end--------

Imports System.Data
Imports System.Data.SqlClient

Public Class PhoneListInfo
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub
Protected WithEvents drptrDIVConst As System.Web.UI.WebControls.Repeater
Protected WithEvents drptrDIVConstRollsParent As System.Web.UI.WebControls.Repeater
Protected WithEvents drptrDIVConstRollsChild As System.Web.UI.WebControls.Repeater

'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Public DS As New DataSet

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
BindData("strDIVConstEmp", "GetDIVContEmp", 1, 0)
BindDataParent("Duties", "GetAllDuties", 1)
BindDataChild("SubDuties", "GetAllSubDuties", "Duties", "DutyID", 1)
End Sub

#Region " Bind Parent Duties "
Sub BindDataParent(ByVal TableName As String, ByVal CommandText As String, ByVal Office As Integer)
Dim SqlConn As New SqlConnection(ConfigurationSettings.AppSettings("s trConn"))
Dim sqlAdapter As New SqlDataAdapter

sqlAdapter.SelectCommand = New SqlCommand
With sqlAdapter.SelectCommand
.Connection = SqlConn
.CommandType = CommandType.StoredProcedure
End With

Dim OfficeID As New SqlParameter("@OfficeId", SqlDbType.BigInt)

'Parameters
OfficeID.Value = Office 'District IV Excutives Offices

With sqlAdapter.SelectCommand
.CommandText = CommandText
.Parameters.Add(OfficeID)
End With

sqlAdapter.Fill(DS, TableName)

With drptrDIVConstRollsParent
.DataSource = DS.Tables(TableName)
End With
Page.DataBind()

SqlConn.Close()

End Sub

#End Region

#Region " Bind Child Sub-Duties "
Sub BindDataChild(ByVal TableNameChild As String, ByVal CommandText As String, ByVal TableNameParent As String, ByVal BindField As String, ByVal Office As Integer)
Dim SqlConn As New SqlConnection(ConfigurationSettings.AppSettings("s trConn"))
Dim sqlAdapter As New SqlDataAdapter

sqlAdapter.SelectCommand = New SqlCommand
With sqlAdapter.SelectCommand
.Connection = SqlConn
.CommandType = CommandType.StoredProcedure
End With

Dim OfficeID As New SqlParameter("@OfficeId", SqlDbType.BigInt)

'Parameters
OfficeID.Value = Office 'District IV Excutives Offices

With sqlAdapter.SelectCommand
.CommandText = CommandText
.Parameters.Add(OfficeID)
End With

sqlAdapter.Fill(DS, TableNameChild)

'Additional Parameters
DS.Relations.Add("myrelation", _
DS.Tables(TableNameParent).Columns(BindField), _
DS.Tables(TableNameChild).Columns(BindField))

With drptrDIVConstRollsChild
.DataSource = DS.Tables(TableNameParent)
End With
Page.DataBind()

SqlConn.Close()

End Sub
#End Region

End Class
Oct 25 '06 #1
0 3839

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Stephen Miller | last post: by
reply views Thread by John Crowley | last post: by
3 posts views Thread by Leigh Webber | last post: by
reply views Thread by Amir | last post: by
8 posts views Thread by I am Sam | last post: by
2 posts views Thread by Hong | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by kermitthefrogpy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.