locked
Controls inside ListView, inside View1, inside Multiview1 RRS feed

  • Question

  • User1555545927 posted

    Hi 

    I have some controls that are inside a ListView

    The ListView is inside a View1 

    The View1 is inside a MultiView1

    (You could make a song out of it Smile)


    How do I find e.g.  a Label control inside the ListView. 

    This line of code worked fine until I threw the ListView inside the MultiView

    ((Label)CartvListView.FindControl("lblSubTotal")).Text = ....


    Thanks for reading

    Thursday, May 13, 2010 11:43 AM

Answers

  • User1564875471 posted

    Try this:

                View View1 = MultiView1.FindControl("View1") as View;
                ListView CartvListView = View1.FindControl("CartvListView") as ListView;
                ((Label)CartvListView.FindControl("lblSubTotal")).Text = "...";


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, May 16, 2010 5:01 PM
  • User1555545927 posted


    Thanks for the answers guys :)

    By the way, I just found out that I don't have any problem accessing controls within a ListView that is itself within a MultiView (don't know why I weren't able to do it before). The procedure is just 'normal procedure' e.g.


    ((Label)CartvListView.FindControl("TotalInclMoms")).Text = "...";


    And Off course this method, provided by 'Anas' works also:

                    View View1 = MultiView1.FindControl("View1") as View;
                    ListView CartvListView = View1.FindControl("IndkoebskurvListView") as ListView;
                    ((Label)CartvListView.FindControl("lblSubTotal")).Text = "Det virker";  


                    View View1 = MultiView1.FindControl("View1") as View;
    
                    ListView CartvListView = View1.FindControl("IndkoebskurvListView") as ListView;
    
                    ((Label)CartvListView.FindControl("lblSubTotal")).Text = "Det virker";  



    Thanks again.


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 17, 2010 1:47 AM

All replies

  • User1564875471 posted

    Try this:

                View View1 = MultiView1.FindControl("View1") as View;
                ListView CartvListView = View1.FindControl("CartvListView") as ListView;
                ((Label)CartvListView.FindControl("lblSubTotal")).Text = "...";


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, May 16, 2010 5:01 PM
  • User-1360095595 posted

    You can't use FindControl directly on a listview.  You have to use it on a specific item from the Items collection.  If it's something you want to do for every item, you'll need to iterate through the items collection and findcontrol on each item.

    Sunday, May 16, 2010 5:07 PM
  • User1564875471 posted

    You can't use FindControl directly on a listview.

    Actually we can.Sometimes we need to get a reference to a control that was placed in the ListView <LayoutTemplate>.In this case, there is no need to specify the item that we are gettting the control from it.


    Sunday, May 16, 2010 5:16 PM
  • User-1360095595 posted

    You can't use FindControl directly on a listview.

    Actually we can.Sometimes we need to get a reference to a control that was placed in the ListView <LayoutTemplate>.In this case, there is no need to specify the item that we are gettting the control from it.

     

    I didn't believe you, but you're right (did a quick test).  I stand corrected.  Having said that, I've never used a control in the LayoutTemplate before.  Never had the need I guess.  But you're absolutely right.  However, in the vast majority of times (read: all times :)), people are looking to find items NOT in the layouttemplate.  At least that's my take on it; maybe because it supports my previous answer more hahaha.

    Sunday, May 16, 2010 5:24 PM
  • User1555545927 posted


    Thanks for the answers guys :)

    By the way, I just found out that I don't have any problem accessing controls within a ListView that is itself within a MultiView (don't know why I weren't able to do it before). The procedure is just 'normal procedure' e.g.


    ((Label)CartvListView.FindControl("TotalInclMoms")).Text = "...";


    And Off course this method, provided by 'Anas' works also:

                    View View1 = MultiView1.FindControl("View1") as View;
                    ListView CartvListView = View1.FindControl("IndkoebskurvListView") as ListView;
                    ((Label)CartvListView.FindControl("lblSubTotal")).Text = "Det virker";  


                    View View1 = MultiView1.FindControl("View1") as View;
    
                    ListView CartvListView = View1.FindControl("IndkoebskurvListView") as ListView;
    
                    ((Label)CartvListView.FindControl("lblSubTotal")).Text = "Det virker";  



    Thanks again.


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 17, 2010 1:47 AM