Solved

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

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video discusses moving either the default database or any database to a new volume.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

746 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