LoginView.FindControl not finding control

Last post 11-28-2006 11:42 PM by ChadThiele. 2 replies.

Sort Posts:

  • LoginView.FindControl not finding control

    11-28-2006, 8:07 PM
    • Participant
      983 point Participant
    • ChadThiele
    • Member since 04-26-2003, 10:43 PM
    • Japan
    • Posts 274

    I'm trying to bind data to a repeater. The repeater is inside a loginView control. Like so:

                <asp:loginview id="loginView" runat="server">
                    <anonymoustemplate>

                        <asp:repeater id="rpLessons" runat="server">
                       
                            <itemtemplate>
                                <div>
                                    <a  href="Default.aspx?lid=<%# Eval("PodID") %>"><%# Eval("Name") %></a><%#Eval("Duration")%>
                                </div>
                            </itemtemplate>
                        </asp:repeater>

                    </anonymoustemplate>
                </asp:loginview>

     I'm binding data to it like so: 

    1    Repeater rpLessons = (Repeater)loginView.FindControl("rpLessons");
    2 rpLessons.DataSource = Lessons();
    3 rpLessons.DataBind();
     

    With the Lessons method looking like this:

    1    private List Lessons()
    2 {
    3 List lessons = new List();
    4 lessons.Add(new Lesson(1, "Once Upon a Time", 9));
    5 lessons.Add(new Lesson(2, "On Another Note", 7));
    6 7 return lessons;
    8 }
     

    And the Lesson class looks like:

    1    public class Lesson
    2 {
    3 public Lesson(int podID, string name, decimal duration)
    4 {
    5 this._podID = podID;
    6 this._name = name;
    7 this._duration = duration;
    8 }
    9 10 private string _name;
    11 12 public string Name
    13 {
    14 get { return _name; }
    15 set { _name = value; }
    16 }
    17 18 private int _podID;
    19 20 public int PodID
    21 {
    22 get { return _podID; }
    23 set { _podID = value; }
    24 }
    25 26 private decimal _duration;
    27 28 public decimal Duration
    29 {
    30 get { return _duration; }
    31 set { _duration = value; }
    32 }
    33 34 }

      But, I'm getting an error: Object reference not set to an instance of an object for line  2 [ rpLessons.DataSource = Lessons(); ]

     Apparently the FindControl method of the LoginView control isn't actually finding the control. Any ideas why not?
     

    Did I answer your question(s)? Phweew...
  • Re: LoginView.FindControl not finding control

    11-28-2006, 11:07 PM
    Answer
    • Star
      9,373 point Star
    • rexlin
    • Member since 07-17-2006, 8:43 AM
    • Posts 1,751


    Best Regards,
    __________________________________________________
    Sincerely,
    Rex Lin
    Microsoft Online Community Support

    This posting is provided "AS IS" with on warranties, and confers no rights.
  • Re: LoginView.FindControl not finding control

    11-28-2006, 11:42 PM
    • Participant
      983 point Participant
    • ChadThiele
    • Member since 04-26-2003, 10:43 PM
    • Japan
    • Posts 274
    Thanks!
    Did I answer your question(s)? Phweew...
Page 1 of 1 (3 items)