Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2007-04-03
6
Medium Priority
?
270 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
Command Line Tips and Tricks

The command line is a powerful tool at the disposal of every Linux user. Although Linux distros come with beautiful user interfaces, it's worthwhile to learn the command line because it allows you to do a number of things that you otherwise cannot do from the GUI.  

 

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 2000 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

670 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