Solved

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

Posted on 2007-04-03
6
251 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Nested forach loop to linq 3 45
Web page design problem 3 42
How do I "share" on social sites? 2 40
XML XDocument extract - Keeping a node list like a menu path 8 34
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

752 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