ADO: Yet another nested repeater newbie

  • woppie / 102 / Fri, 27 Mar 2009 21:50:00 GMT / Comments (1)
  • I know that there is unlimited of forum-treads about solutions to nested repeater problems.
    Still, I just can't get it to work.

    I really hope that someone could guide me to the right solution for creating a nested repeater once and for all

    Error:

    "Object reference not set to an instance of an object."

    Source Error:
    "Line 14: Dim cmd2 As Data.SqlClient.SqlDataAdapter = New Data.SqlClient.SqlDataAdapter("SELECT * from tblRegions", cnn)
    Line 15: cmd2.Fill(ds, "ID")
    Line 16: ds.Relations.Add("myrelation", _
    Line 17: ds.Tables("Links").Columns("ParentCategory"), _
    Line 18: ds.Tables("tblRegions").Columns("ID"))"

    My code:

    test.aspx

    <%... Page Language="VB" AutoEventWireup="false" MasterPageFile="~/MasterPage.master" CodeFile="test.aspx.vb" Inherits="test" %
    <asp:Content ID="ContentTest" ContentPlaceHolderID="ContentMain" Runat="Server"
    <asp:Repeater ID="parentRepeater" runat="server">
    <ItemTemplate>
    <b>
    <%#DataBinder.Eval(Container.DataItem, "ID")%>
    </b>
    <br>
    <asp:Repeater ID="childRepeater" runat="server" DataSource='<%# Container.DataItem.Row.GetChildRows("myrelation") %>'>

    <ItemTemplate>
    <%#Container.DataItem("ID")%>
    <br>
    </ItemTemplate>
    </asp:Repeater>
    </ItemTemplate>
    </asp:Repeater
    </asp:Content
    Test.aspx.vb

    Public Class test
    Inherits System.Web.UI.Page

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim cnn As Data.SqlClient.SqlConnection = New Data.SqlClient.SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings("GetCategoriesConnectionString").ConnectionString)
    cnn.Open()

    Dim cmd1 As Data.SqlClient.SqlDataAdapter = New Data.SqlClient.SqlDataAdapter("SELECT * from Links", cnn)
    Dim ds As New Data.DataSet()
    cmd1.Fill(ds, "ParentCategory")

    Dim cmd2 As Data.SqlClient.SqlDataAdapter = New Data.SqlClient.SqlDataAdapter("SELECT * from tblRegions", cnn)
    cmd2.Fill(ds, "ID")
    ds.Relations.Add("myrelation", _
    ds.Tables("Links").Columns("ParentCategory"), _
    ds.Tables("tblRegions").Columns("ID"))
    parentRepeater.DataSource = ds.Tables("Links")

    parentRepeater.DataSource = ds.Tables("Links")
    Page.DataBind()
    cnn.Close()

    End Sub

    End Class

  • Keywords:

    nested, repeater, newbie, ado

  • http://dotnet.itags.org/dotnet-ado/36/«« Last Thread - Next Thread »»
    1. Hi,Woppie:

      ds.Relations.Add("myrelation", _
      Line 17: ds.Tables("Links").Columns("ParentCategory"), _
      Line 18: ds.Tables("tblRegions").Columns("ID"))"

      I do not see the datatable Links and tblRegions in your ds above.

      According to the following code you have, i suppose the name of the datatable is ParentCategory and ID.

      cmd1.Fill(ds, "ParentCategory")

      cmd2.Fill(ds, "ID")

      rexlin | Sun, 06 Jan 2008 00:26:00 GMT |