This is a migrated thread and some comments may be shown as answers.

Subject Hyperlink based on data value - how?

11 Answers 136 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Steve asked on 15 Aug 2008, 11:13 AM
I'm using the scheduler with a SharePoint List as the datasource. I want to show a hyperlink for the Subject but it should only be a hyperlink if another Field in the ListItem is a certain value.

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

Sort by
0
Steve
Top achievements
Rank 1
answered on 19 Aug 2008, 01:45 PM
Can someone point in the right direction of how to add hyperlinks to appointments based on a value in the datasource?

cheers,

Steve
0
Accepted
Peter
Telerik team
answered on 19 Aug 2008, 03:21 PM
Hello 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.
0
Steve
Top achievements
Rank 1
answered on 20 Aug 2008, 07:51 AM
Thanks Peter, this fixed it.
0
Steve
Top achievements
Rank 1
answered on 20 Aug 2008, 12:28 PM
Peter, one more thing from this. Can I get access to the Appointment object in this Template code?

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
0
Steve
Top achievements
Rank 1
answered on 20 Aug 2008, 01:51 PM
Peter, I managed to get it working by casting the parent like this:

        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
0
Peter
Telerik team
answered on 21 Aug 2008, 01:18 PM
Hello 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.
0
Archan
Top achievements
Rank 1
answered on 12 Sep 2008, 10:23 AM
hi

 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
0
Peter
Telerik team
answered on 15 Sep 2008, 12:53 PM
Hi 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.
0
Archan
Top achievements
Rank 1
answered on 18 Sep 2008, 06:21 AM
Thanks..
It is working now..


Archan
0
Archan
Top achievements
Rank 1
answered on 18 Sep 2008, 12:15 PM
Hi peter

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

0
Peter
Telerik team
answered on 19 Sep 2008, 07:55 AM
Hello 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.
Tags
Scheduler
Asked by
Steve
Top achievements
Rank 1
Answers by
Steve
Top achievements
Rank 1
Peter
Telerik team
Archan
Top achievements
Rank 1
Share this question
or