?
Solved

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

Posted on 2012-04-04
4
Medium Priority
?
299 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
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…
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.
Suggested Courses

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