• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1264
  • Last Modified:

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

0
cameroz2887
Asked:
cameroz2887
  • 3
1 Solution
 
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
 
cameroz2887Author Commented:
I tried it and it worked perfect for me.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now