Solved

Where to databind and how to create the relationship between nested repeaters

Posted on 2007-04-03
6
262 Views
Last Modified: 2010-05-18
This is a nesting repeater problem. I don't understand where I indicate the relation between the inner and outer repeaters, and I also can't figure out when/where to instantiate the datasource for each repeater.

I would like to call two separate stored procedures for each repeater. I would like to pass the Collection_ID from the parent repeater to the InnerRepeater.

I'm using vb.net.

My aspx page looks like this:
        <asp:Repeater ID="ParentRepeater" runat="server" OnItemDataBound="rParent_ItemDataBound">
        <HeaderTemplate>
        <table style="LEFT: 178px; WIDTH: 980px; POSITION: absolute; TOP: 195px" id="DataTable">
        <tr>
        <th class="intraContent"><b>Action</b></th>
        <th class="intraContent"><b>Collection Name</b></th>
        <th class="intraContent"><b>Current Version</b></th>
        <th class="intraContent"><b>Description</b></th>
        <th class="intraContent"><b>Lifecycle </b></th>
        <th class="intraContent"><b>Environment</b></th>
        <th class="intraContent"><b>Released On</b></th>
        <th class="intraContent"><b>Published On </b></th>
        <th class="intraContent"><b>Packages</b></th>
        <th class="intraContent"><b>Queries</b></th>
        <th class="intraContent"><b>Hosts</b></th>
        </tr>
       
        </headertemplate>
        <ItemTemplate>
        <tr>
        <td class="intraContent">

        <asp:repeater ID="InnerRepeater" runat="Server">
        <ItemTemplate>
        <%# DataBinder.Eval(Container.DataItem, "OBJECT_ACTION") %>

        </ItemTemplate>
        </asp:repeater>
        </td>
        <td class="intraContent" onmouseover="this.className='intraContentHover'" onmouseout="this.className='intraContent'"><%#DataBinder.Eval(Container.DataItem, "COLLECTION_NAME")%></td>
       
        <td class="intraContent" align="center" style="border-bottom: 2px solid #D3D3D3" onmouseover="this.className='intraContentHover'" onmouseout="this.className='intraContent'"><%#DataBinder.Eval(Container.DataItem, "Current_Version")%></td>
        <td class="intraContent" align="center" style="border-bottom: 2px solid #D3D3D3" onmouseover="this.className='intraContentHover'" onmouseout="this.className='intraContent'"><%#DataBinder.Eval(Container.DataItem, "DESCRIPTION")%></td>
        <td class="intraContent" align="center" style="border-bottom: 2px solid #D3D3D3" onmouseover="this.className='intraContentHover'" onmouseout="this.className='intraContent'"><%#DataBinder.Eval(Container.DataItem, "LIFECYCLE")%></td>
        <td class="intraContent" align="center" style="border-bottom: 2px solid #D3D3D3" onmouseover="this.className='intraContentHover'" onmouseout="this.className='intraContent'"><%#DataBinder.Eval(Container.DataItem, "ENVIRONMENT")%></td>
        <td class="intraContent" align="center" style="border-bottom: 2px solid #D3D3D3" onmouseover="this.className='intraContentHover'" onmouseout="this.className='intraContent'"><% Response.Write("????")%></td>
        <td class="intraContent" align="center" style="border-bottom: 2px solid #D3D3D3" onmouseover="this.className='intraContentHover'" onmouseout="this.className='intraContent'"><%#DataBinder.Eval(Container.DataItem, "PUBLISHED_ON")%></td>
        <td class="intraContent" align="center" style="border-bottom: 2px solid #D3D3D3" onmouseover="this.className='intraContentHover'" onmouseout="this.className='intraContent'"><asp:linkbutton runat="server" ID="linkButtonc1" CssClass="lnkbutton" CommandName="PACKAGES_COUNT" CommandArgument='<%# DataBinder.Eval(Container.DataItem,"COLLECTION_ID") %>'><%#DataBinder.Eval(Container.DataItem, "PACKAGES")%></asp:linkbutton></td>
        <td class="intraContent" align="center" style="border-bottom: 2px solid #D3D3D3" onmouseover="this.className='intraContentHover'" onmouseout="this.className='intraContent'"><asp:linkbutton runat="server" ID="linkButtonc2" CssClass="lnkbutton" CommandName="QUERIES_COUNT" CommandArgument='<%# DataBinder.Eval(Container.DataItem,"COLLECTION_ID") %>'><%#DataBinder.Eval(Container.DataItem, "QUERIES")%></asp:linkbutton></td>
        <td class="intraContent" align="center" style="border-bottom: 2px solid #D3D3D3" onmouseover="this.className='intraContentHover'" onmouseout="this.className='intraContent'"><asp:linkbutton runat="server" ID="linkButtonc3" CssClass="lnkbutton" CommandName="HOSTS_COUNT" CommandArgument='<%# DataBinder.Eval(Container.DataItem,"COLLECTION_ID") %>'><%#DataBinder.Eval(Container.DataItem, "HOSTS") %></asp:linkbutton></td>
        </tr>
        </ItemTemplate>
        <FooterTemplate>
       
        </table>
        </FooterTemplate>
        </asp:Repeater>


...and the code behind file looks like this:
    Protected Sub LoadData()
        Dim conn As New SqlConnection
        Dim cmd As New SqlCommand
        Dim connstring As String
        Dim da As New SqlDataAdapter
        Dim dt As New DataTable

        connstring = Connector.ConnectStringBuild
        conn.ConnectionString = connstring
        cmd.Connection = conn
        cmd.CommandText = "ACT_GET_COLLECTION_DETAILS"
        cmd.CommandType = CommandType.StoredProcedure


        cmd.Parameters.Add("@SERVICE_ID", SqlDbType.Int).Value = SetVars.Service_ID
        cmd.Parameters.Add("@LOGON_NAME", SqlDbType.VarChar).Value = SetVars.UserName
        cmd.Parameters.Add("@INDICATOR", SqlDbType.VarChar).Value = SetVars.Indicator

        conn.Open()
        da.SelectCommand = cmd
        da.Fill(dt)

        Me.ParentRepeater.DataSource = dt
        Me.ParentRepeater.DataBind()
        conn.Close()




    End Sub
    Protected Function ChildData() As DataTable
        Dim conn As New SqlConnection
        Dim cmd As New SqlCommand
        Dim connstring As String
        Dim da As New SqlDataAdapter
        Dim dt As New DataTable

        Dim childa As New SqlDataAdapter
        connstring = Connector.ConnectStringBuild
        conn.ConnectionString = connstring
        cmd.Connection = conn
        cmd.CommandText = "ACT_GET_FUNCTION_SERVICE_DETAILS"
        cmd.CommandType = CommandType.StoredProcedure

        cmd.Parameters.Add("@GROUP_NAME", SqlDbType.VarChar).Value = SetVars.GroupName
        cmd.Parameters.Add("@SERVICE_ID", SqlDbType.Int).Value = SetVars.Service_ID
        cmd.Parameters.Add("@OBJECT_NAME", SqlDbType.VarChar).Value = "COLLECTION"
        cmd.Parameters.Add("@COLLECTION_ID", SqlDbType.Int).Value = 7
        conn.Open()
        childa.SelectCommand = cmd
        childa.Fill(dt)

        Return dt

        conn.Close()
        conn = Nothing
        cmd = Nothing

    End Function
    Protected Sub rParent_ItemDataBound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs)
        Dim conn As New SqlConnection
        Dim cmd As New SqlCommand
        Dim connstring As String
        Dim da As New SqlDataAdapter
        Dim dt As New DataTable

        connstring = Connector.ConnectStringBuild
        conn.ConnectionString = connstring
        cmd.Connection = conn
        cmd.CommandText = "ACT_GET_COLLECTION_DETAILS"
        cmd.CommandType = CommandType.StoredProcedure


        cmd.Parameters.Add("@SERVICE_ID", SqlDbType.Int).Value = SetVars.Service_ID
        cmd.Parameters.Add("@LOGON_NAME", SqlDbType.VarChar).Value = SetVars.UserName
        cmd.Parameters.Add("@INDICATOR", SqlDbType.VarChar).Value = SetVars.Indicator

        conn.Open()
        da.SelectCommand = cmd
        da.Fill(dt)
        'Me.ParentRepeater.DataSource = dt
        'Me.ParentRepeater.DataBind()
        conn.Close()

        If (e.Item.ItemType = ListItemType.Item) Or (e.Item.ItemType = ListItemType.AlternatingItem) Then
            Dim r As Repeater = CType(e.Item.FindControl("InnerRepeater"), Repeater)
            r.DataSource = ChildData()
            r.DataBind()

        End If
    End Sub


NB: ChildData() is a class that returns a datatable. It is executing another stored procedure separate from the one for the parent repeater.
0
Comment
Question by:rss2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 37

Expert Comment

by:samtran0331
ID: 18842799
would this help?
http://support.microsoft.com/kb/326338

I'm not sure if it meets your data requirement:
"I would like to pass the Collection_ID from the parent repeater to the InnerRepeater."

It does the relation using an ado datarelation and then binds the child to the parent using:
Container.DataItem.Row.GetChildRows("myrelation")
0
 

Author Comment

by:rss2
ID: 18842926
No that doesn't really help me because the problem I'm having is creating the relation between the two datasets, but using stored procedure calls instead of embedded SQL.

I would like to see how to create the two necessary datatsets using stored procedures, then creating the relationship between the two datasets (i.e. without the reference to a table..perhaps with the use of a table index?), and then binding the data.

Thanks anyway!
0
 
LVL 37

Expert Comment

by:samtran0331
ID: 18846305
no I wouldn't recommend using a table/row index...if your primary key isn't always inline with the number of rows...all kinds of bad things happen...

what is the primary key field for the child repeater/datataset?
is it Service_ID? (hope so)

because I think you almost have it, but ChildData would need to receive a parameter like:
ChildData(SetVars.Service_ID)

and it would stay in your rParent_ItemDataBound event

keep in mind that calling a stored procedure for all the children mean multiple calls to the db (one call for each child)...where if you do it like the MSDN article, you have a total of 2 calls to the db...
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

Author Comment

by:rss2
ID: 18851610
It's working now..sort of.

I'll post the code in a sec for others but could you help me with display issues I'm having..

The inner repeater is supposed to populate a dropdownlist. At the moment I have the inner repeater returning the correct data but only in a list. How do I get that information into a drop down list?

Here's what my aspx page has for the inner repeater:
        <asp:Repeater ID="InnerRepeater" runat="Server">
        <ItemTemplate>
        <tr>
        <td class="intraContent">
<%#DataBinder.Eval(Container.DataItem, "OBJECT_ACTION")%>
        </td>
</itemtemplate>
</asp:Repeater>

...so it is the OBJECT_ACTION values which I would like to put into <asp:DropDownList> I have tried everything and can't get it to work!

Thanks,
rss2
0
 
LVL 37

Accepted Solution

by:
samtran0331 earned 500 total points
ID: 18852003
what have you tried?

First replace:
<%#DataBinder.Eval(Container.DataItem, "OBJECT_ACTION")%>
with a dropdownlist...then...

in your rParent_ItemDataBound, you use findcontrol to get the child repeater...you need to do the same thing to "findcontrol" the dropdownlist inside the child repeater you dimmed as "r"...
then bind the dropdownlist and set the correct value

0
 

Author Comment

by:rss2
ID: 18856698
Ok.. now it's complaining about using the "New" keyword?

Here is my code:
    Protected Sub ParentRepeater_ItemDataBound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs)

        If (e.Item.ItemType = ListItemType.Item) Or (e.Item.ItemType = ListItemType.AlternatingItem) Then
            Dim r As Repeater = CType(e.Item.FindControl("InnerRepeater"), Repeater)
            r.DataSource = ChildData()
            r.DataBind()
            Dim theDropDownList As New DropDownList
            theDropDownList = CType(FindControl("ActionDropDownList"), DropDownList)
            theDropDownList.DataSource = r.DataSource
            theDropDownList.DataBind()

        End If

    End Sub

It doesn't like this line:
theDropDownList.DataSource = r.DataSource
It says "Object reference not set to an instance of an object"
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

617 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