This is a migrated thread and some comments may be shown as answers.
Simple List DataSource not working
1 Answer 15 Views
This is a migrated thread and some comments may be shown as answers.
Adam
Top achievements
Rank 1
Adam asked on 05 Mar 2010, 07:45 PM
(Hopefully) Quick problem:

    <form id="form1" runat="server"
    <div> 
        <telerik:RadScheduler ID="RS1" AllowEdit="false" 
            ShowHeader="false" FirstDayOfWeek="Monday" LastDayOfWeek="Sunday" ShowNavigationPane="false"  
            ShowViewTabs="false" SelectedView="WeekView" ShowFooter="false" ShowAllDayRow="false"  
            DataKeyField="ID" DataSubjectField="Subject" DataEndField="End" DataStartField="Start"  
            runat="server" WeekView-ColumnHeaderDateFormat="ddd" > 
        </telerik:RadScheduler> 
    </div> 
    </form> 

public partial class Test : System.Web.UI.Page 
    public class ItemSchedule 
    { 
        public string Subject; 
        public DateTime Start; 
        public DateTime End; 
        public string ID; 
        public ItemSchedule(string subject, DateTime start, DateTime end) 
        { 
            Subject = subject; 
            Start = start; 
            End = end; 
            ID = Guid.NewGuid().ToString(); 
        } 
    } 
    protected void Page_Load(object sender, EventArgs e) 
    { 
        List<ItemSchedule> items = new List<ItemSchedule>(); 
        items.Add(new ItemSchedule("test", DateTime.Now, DateTime.Now.AddHours(1))); 
        RS1.DataSource = items; 
    } 

Error says: 

DataBinding: 'Test+ItemSchedule' does not contain a property with thename 'ID'.


I do have a public property with the name of ID in my class (despite it being supposedly optional according to http://www.telerik.com/help/aspnet-ajax/schedule_databinding.html) but I must be missing something...
If possible I'd like to not even have an ID, but otherwise...why doesn't this work?

1 Answer, 1 is accepted

Sort by
0
Accepted
Adam
Top achievements
Rank 1
answered on 08 Mar 2010, 09:15 PM
Turns out this is not really specific to Telerik controls.
Anything using the .Net DataBind() method requires public properties (not 'fields') for data binding to work.
The solution was to encapsulate all the public fields with set and get methods:

    public class ItemSchedule 
    { 
        public string Subject { getset; } 
        public DateTime Start{ getset; } 
        public DateTime End{ getset; } 
        public string ID{ getset; } 
        public ItemSchedule(string subject, DateTime start, DateTime end) 
        { 
            Subject = subject; 
            Start = start; 
            End = end; 
            ID = Guid.NewGuid().ToString(); 
        } 
    } 

Kinda silly I guess, but there ya go.
Asked by
Adam
Top achievements
Rank 1
Answers by
Adam
Top achievements
Rank 1
Share this question
or