Hello All,
I'm new to C# and to Telerik. My problem is that I'm modifying the supplied code to bind a datagrid to the scheduler's data. Heres my code:
//Create a dynamic table to store the appointments' information:
DataTable table1 = new DataTable();
table1.Columns.Add("ID");
table1.Columns.Add("Instructor");
foreach (Appointment a in RadScheduler1.Appointments)
{
if (a.RecurrenceState == RecurrenceState.Master)
{
RecurrenceRule parsedRule;
RecurrenceRule.TryParse(a.RecurrenceRule.ToString(), out parsedRule);
//If a recurring appointment does not have specified end time it will have
//endless occurrences. In this case you can explicitly put a restriction:
//parsedRule.SetEffectiveRange(DateTime.Now.AddYears(-1), DateTime.Now.AddYears(1));
foreach (DateTime occurrence in parsedRule.Occurrences)
{
table1.Rows.Add(new string[] { a.Subject.ToString(), occurrence.ToString(), occurrence.Add(a.Duration).ToString() });
}
}
else
if (a.RecurrenceState != RecurrenceState.Occurence)
{
//table1.Rows.Add(new string[] { a.Attributes["ID"].ToString(), a.Attributes["Instructor"].ToString() });
string x = a.Attributes["Instructor"].ToString();
table1.Rows.Add(new string[] { a.Subject.ToString() });
}
}
GridView1.DataSource = table1;
GridView1.DataBind();
}
The problem is that I get a NULL reference exception when trying to include the "Attributes" to the datagrid. For instance:
table1.Rows.Add(new string[] { a.Subject.ToString() }); works, but
table1.Rows.Add(new string[] { a.Attributes["ID"].ToString() }); doesn't work. Why?? And how do I get around it??
I'm new to C# and to Telerik. My problem is that I'm modifying the supplied code to bind a datagrid to the scheduler's data. Heres my code:
//Create a dynamic table to store the appointments' information:
DataTable table1 = new DataTable();
table1.Columns.Add("ID");
table1.Columns.Add("Instructor");
foreach (Appointment a in RadScheduler1.Appointments)
{
if (a.RecurrenceState == RecurrenceState.Master)
{
RecurrenceRule parsedRule;
RecurrenceRule.TryParse(a.RecurrenceRule.ToString(), out parsedRule);
//If a recurring appointment does not have specified end time it will have
//endless occurrences. In this case you can explicitly put a restriction:
//parsedRule.SetEffectiveRange(DateTime.Now.AddYears(-1), DateTime.Now.AddYears(1));
foreach (DateTime occurrence in parsedRule.Occurrences)
{
table1.Rows.Add(new string[] { a.Subject.ToString(), occurrence.ToString(), occurrence.Add(a.Duration).ToString() });
}
}
else
if (a.RecurrenceState != RecurrenceState.Occurence)
{
//table1.Rows.Add(new string[] { a.Attributes["ID"].ToString(), a.Attributes["Instructor"].ToString() });
string x = a.Attributes["Instructor"].ToString();
table1.Rows.Add(new string[] { a.Subject.ToString() });
}
}
GridView1.DataSource = table1;
GridView1.DataBind();
}
The problem is that I get a NULL reference exception when trying to include the "Attributes" to the datagrid. For instance:
table1.Rows.Add(new string[] { a.Subject.ToString() }); works, but
table1.Rows.Add(new string[] { a.Attributes["ID"].ToString() }); doesn't work. Why?? And how do I get around it??