Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Please explain "Multi-Tenant Services" 5 65
Tool Box 2 35
Host asp.net pages 5 26
VB.Net - Windows UserName index and length error 4 24
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

863 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

25 Experts available now in Live!

Get 1:1 Help Now