repeater inside a repeater problem.

Discussion in '.NET' started by uncensored, Oct 25, 2006.

  1. uncensored

    uncensored

    Joined:
    Oct 25, 2006
    Messages:
    4
    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("strConn"))
    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)
    '.DataBind()
    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("strConn"))
    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))

    'drptrDIVConstRollsChild = New System.Web.UI.WebControls.Repeater

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

    SqlConn.Close()

    End Sub
    #End Region

    End Class
     
    uncensored, Oct 25, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stephen Miller
    Replies:
    2
    Views:
    5,227
    Stevie_mac
    Aug 16, 2003
  2. voidfill3d@yahoo.com

    Repeater inside a repeater....how?

    voidfill3d@yahoo.com, Aug 10, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    7,033
    Karl Seguin
    Aug 10, 2005
  3. HockeyFan
    Replies:
    1
    Views:
    1,000
    Masudur
    Jul 4, 2007
  4. Korel Oktar
    Replies:
    0
    Views:
    1,942
    Korel Oktar
    Jan 21, 2008
  5. Microsoft

    Repeater inside a Repeater

    Microsoft, Aug 21, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    210
    Microsoft
    Aug 21, 2006
Loading...

Share This Page