Reference Nested Listview Controls

Hello, this is my first question, so please excuse me if I don't ask it correctly.  I have a listview nested in another listview.  I am passing a value from the outer listview to the inner listview via code behind.  Everything works as it should when I run it.  The outer listview populates the data, and when there is data from the inner listview that should show, it does.  However, every outerlistview does not populate an inner listview.  When I try to reference a control in the innerlistview, it says "Object reference not set to an instance of an object".

Is there a way to reference a control in the innerlistview ONLY if the innerlistview has data to display?  I think this may be my problem, but I of course may be wrong.
' Inner list View
            Dim StageRepliesLv As ListView = CType(e.Item.FindControl("StageRepliesLv"), ListView)

            ' Inner list View Data Source
            Dim StageRepliesDs As SqlDataSource = CType(e.Item.FindControl("StageRepliesDs"), SqlDataSource)

            ' Finding the SelectParameter to pass from Outer to Inner Listview
            Dim CommentId As String = rowView("CommentId").ToString()

            ' Passing the value to the SelectParameter of the Inner Listview
            StageRepliesDs.SelectParameters("CommentId").DefaultValue = CommentId

            ' Trying to reference a control in the Inner Listview
            ' I think it may be because not every Outer Listview will have an Inner Listview
            ' populate data.
            Dim ReplyDateLbl As Label = CType(e.Item.FindControl("StageRepliesLv").FindControl("ReplyDateLbl"), Label)


            ReplyDateLbl.Text = "working"

Open in new window

cameroz2887Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cameroz2887Author Commented:
Thank you for responding agarwalrahul.  I checked the links you provided, and being that I am just so new to this, It wasn't able to help me out.  My problem is I can not reference a control in the inner listview.  I can reference the inner listview, but just can't seem to reference a control in that inner listview.  Everything else is working great.

Since the inner listview will NOT always be shown (being it is for replies to comments), is there another way I should be writing my code above, to reference the control "ReplyDateLbl" that is in the inner listview?
0
cameroz2887Author Commented:
Thanks for staying on top of this Moderator.  I did find a solution to referencing the nested listview controls.

I set OnItemDataBound = "NestedListview_ItemDataBound" for the nested listview.

Then in the codebehind,

Protected Sub NestedListview_ItemDataBound(sender As Object, e As System.Web.UI.WebControls.ListViewItemEventArgs)

Then I was able to access the controls.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cameroz2887Author Commented:
I tried it and it worked perfect for me.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.