I got this code from another post:
protected void Page_Load(object sender, EventArgs e) |
{ |
RadScheduler1.AppointmentTemplate = new AppTemplate(); |
} |
public class AppTemplate : ITemplate |
{ |
private Literal subject; |
public void InstantiateIn(Control container) |
{ |
subject = new Literal(); |
subject.DataBinding += subject_DataBinding; |
container.Controls.Add(subject); |
} |
private void subject_DataBinding(object sender, EventArgs e) |
{ |
IDataItemContainer aptContainer = (IDataItemContainer)subject.BindingContainer; |
int lId = (int)DataBinder.Eval(aptContainer.DataItem, "ID"); |
string strSubject = HttpUtility.HtmlEncode((string)DataBinder.Eval(aptContainer.DataItem, "Subject")); |
SPWeb oWeb = null; |
oWeb = SPContext.Current.Web; |
String requestListName = "TravelCalendarList"; |
SPListItem itm = oWeb.Lists[requestListName].GetItemById(Convert.ToInt32(lId)); |
if (itm != null) |
{ |
if (null != itm["RequestId"]) |
{ |
subject.Text = "<a href=\"" + oWeb.Url + "/default.aspx?ListId=" + lId + "\">" + strSubject + "</a>"; |
} |
else |
{ |
subject.Text = strSubject; |
} |
} |
} |
} |
I added a breakpoint to subject_DataBinding and although I have 3 items returned from the SharePoint List (and I can see them correctly plotted in the Scheduler), the values that are returned in subject_DataBinding are always the same. Therefore it only applies a hyperlink to one Subject, the rest are blank.
Any ideas what I'm doing wrong here?
11 Answers, 1 is accepted
cheers,
Steve
Please, modify your code as follows and let us know how it goes.
public class AppTemplate : ITemplate |
{ |
public void InstantiateIn(Control container) |
{ |
Literal subject = new Literal(); |
subject.DataBinding += subject_DataBinding; |
container.Controls.Add(subject); |
} |
private void subject_DataBinding(object sender, EventArgs e) |
{ |
Literal subject = (Literal)sender; |
IDataItemContainer aptContainer = (IDataItemContainer)subject.BindingContainer; |
int lId = (int)DataBinder.Eval(aptContainer.DataItem, "ID"); |
string strSubject = HttpUtility.HtmlEncode((string)DataBinder.Eval(aptContainer.DataItem, "Subject")); |
SPWeb oWeb = null; |
oWeb = SPContext.Current.Web; |
String requestListName = "TravelCalendarList"; |
SPListItem itm = oWeb.Lists[requestListName].GetItemById(Convert.ToInt32(lId)); |
if (itm != null) |
{ |
if (null != itm["RequestId"]) |
{ |
subject.Text = "<a href=\"" + oWeb.Url + "/default.aspx?ListId=" + lId + "\">" + strSubject + "</a>"; |
} |
else |
{ |
subject.Text = strSubject; |
} |
} |
} |
} |
Kind regards,
Peter
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
For example, when I set the hyperlink I want to set the Appointment security so that the user cannot edit or delete the Appointment. Otherwise, if it's not a hyperlink I want to enable edit and delete as normal.
cheers,
Steve
Literal subject = (Literal)sender; |
IDataItemContainer aptContainer = (IDataItemContainer)subject.BindingContainer; |
SchedulerAppointmentContainer aptCont = (SchedulerAppointmentContainer)subject.Parent; |
Appointment app = aptCont.Appointment; |
Although this works fine and allows me to set AllowEdit and AllowDelete on the Appointments in the template, is this the best method?
cheers,
Steve
That's a nice solution. I wasn't sure how you could implement this, but now that I tested your approach I don't see a reason why not to use it. Actually, I will consider preparing a KB article out of this case.
Thanks!
Peter
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
I have implemented this thing and it is working fine for Month View but my Weekly view and daily view stopped working.
Please help me out..This is urgent ...
Thanks in Advance
Archan
You can download a working sample project from this kb article. Let us know if you still have questions.
Greetings,
Peter
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
It is working now..
Archan
I am still facing some issues with the schedular :--
I am pasting the code here :---
<AppointmentTemplate>
<a href = "Details.aspx?chngid=<%# Eval("ID")%>" target ="_blank" >
(
<asp:Literal ID="AppointmentStartTime" runat="server" Text='<%# Eval("Start", "{0:t}") %>'></asp:Literal>
-
<asp:Literal ID="AppoitmentEndTime" runat="server" Text='<%# Eval("End", "{0:t}") %>'></asp:Literal>)
<asp:Literal ID="AppointmentSubject" runat="server" Text='<%# Eval("Subject") %>'></asp:Literal>
</a>
</br>
</AppointmentTemplate>
The CS code I have used is same as in the KB article...
I want the month view to look as above and other views as I have implemented in the Class as defined in the Article..
After doing this the DAY,WEEK and Month Navigation is not working.
Show 24 hours in Day View is not working..
Please help me out.
Thanks in Advance
Archan
You use double quotes twice in:
<a href="Details.aspx?chngid=<%# Eval("ID")%>"
Please, try single quotes for the ID:
<a href="Details.aspx?chngid=<%# Eval('ID')%>"
Best wishes,
Peter
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.