Solved

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

Posted on 2012-04-04
4
294 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

739 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