Solved

Reference a label control in a datalist that is inside another datalist

Posted on 2012-04-04
4
296 Views
Last Modified: 2012-08-14
Webpage, VB.Net, ASP.NET

I have a datalist (dList3) inside another datalist (DataList1).  I need to reference a label control in the "inside" datalist (dList3).  I'm trying to do that in the DataList1_ItemDataBound but it is not working.  I'm assuming that is because the dlist3 hasn't been populated yet when calling DataList1_ItemDataBound.

Objective: To get the label "OpDisplay" which is a label in the DataList "dList3".

My Code:
Protected Sub DataList1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles DataList1.ItemDataBound

        If e.Item.ItemType = ListItemType.Item Or _
            e.Item.ItemType = ListItemType.AlternatingItem Then
            Dim ds As SqlDataSource
            ds = CType(e.Item.FindControl("DetailsDataSource"),  _
                SqlDataSource)

            ds.ConnectionString = ConfigurationManager.ConnectionStrings("SQL2005_690222_ccmConnectionString").ConnectionString

            Dim categoryID As String
            categoryID = DataBinder.Eval(e.Item.DataItem, _
                "OrderID").ToString()
            ds.SelectParameters("OrdDetailOrderID").DefaultValue = _
                categoryID
        End If
        Dim lbDelType As Label = CType(e.Item.FindControl("OrderDelTypeLabel"), Label)
        Dim strABC = lbDelType.Text
       
        Dim dlList3 As DataList = CType(e.Item.FindControl("DataList3"), DataList)

        Dim lblOpDisplay() As Label

        Dim dlList3Count As Integer = dlList3.Items.Count
        For v = 1 To dlList3Count
            lblOpDisplay(v) = dlList3.Controls(v - 1).FindControl("OpDisplay")

            If lblOpDisplay(v).Text = "x" Then
                lblOpDisplay(v).Text = ""
            Else
                lblOpDisplay(v).Text = "Hello"
            End If
        Next

    End Sub
0
Comment
Question by:PrimeNY
[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
4 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37808176
What does the count come back as?
0
 

Author Comment

by:PrimeNY
ID: 37808197
comes back as "0"
0
 

Accepted Solution

by:
PrimeNY earned 0 total points
ID: 37808644
I figured it out.  Added " dlList3.DataBind()" to the code in "DataList1_ItemDataBound".
0
 

Author Closing Comment

by:PrimeNY
ID: 37822768
I figured it out.  Added " dlList3.DataBind()" to the code in "DataList1_ItemDataBound".
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

696 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