Solved

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

Posted on 2007-04-03
6
228 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
  • 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now