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...