0

I want to display report in Jquery calender control in ASP.net for that I need to retrieve data from Database .I wrote a service like this

    [WebMethod]
public static string GetData()
{
    Horticulture h = new Horticulture();
    return h.GetProjectedYield().GetXml();
}

Here I'm converting dataset to xml and then I'm calling that function in javascript as follows

 $(document).ready(function () {
 var response;
     $.ajax({
         type: 'POST',
         dataType: 'json',
         contentType: 'application/json',
         url: 'ProjectedYieldCalender.aspx/GetData',
         data: '{}',
         success:
                function (res) {
                    var xmlDoc = $.parseXML(res.d);                      
                    var xml = $(xmlDoc);
                    var customers = xml.find("Table1");
                }

     });

And then I need to bind the retrived data to JQuery Calender control as follows

$('#calendar').fullCalendar({
         header: {
             left: 'prev,next today',
             center: 'title',
             right: 'month,basicWeek,basicDay'
         },
         //defaultDate: '2014-08-12',
         editable: true,
         eventLimit: true, // allow "more" link when too many events
         events: [
               for(var i=0; i<customers.length; i++)
            {
            "{"

                "title:" +customers[i].Column1+","
                "start:"+customers[i].Column3
                "}"


            if(i!=customers.length-1)
            {
                ","
            }   

            }

    ]
     });

 });

but I'm not getting the proper output (unable to find) but I need to generate this as follows

$(document).ready(function() {

    $('#calendar').fullCalendar({
        defaultDate: '2014-11-12',
        editable: true,
        eventLimit: true, // allow "more" link when too many events
        events: [
            {
                title: 'All Day Event',
                start: '2014-11-01'
            },
            {
                title: 'Long Event',
                start: '2014-11-07',
                end: '2014-11-10'
            },
            {
                id: 999,
                title: 'Repeating Event',
                start: '2014-11-09T16:00:00'
            },
            {
                id: 999,
                title: 'Repeating Event',
                start: '2014-11-16T16:00:00'
            },
            {
                title: 'Conference',
                start: '2014-11-11',
                end: '2014-11-13'
            },
            {
                title: 'Meeting',
                start: '2014-11-12T10:30:00',
                end: '2014-11-12T12:30:00'
            },
            {
                title: 'Lunch',
                start: '2014-11-12T12:00:00'
            },
            {
                title: 'Meeting',
                start: '2014-11-12T14:30:00'
            },
            {
                title: 'Happy Hour',
                start: '2014-11-12T17:30:00'
            }
        ]
    });

});

Can any one please let e know how to do this ? Where am I going wrong?

1 Answer 1

1

Make it simple - do not return XML in web service, return List of event objects.

public class CEvent
{
    public int id {get;set;}
    public string title {get;set;}
    public DateTime start {get;set;}
}

[WebMethod]
public List<CEvent> GetData()
{
    return new List<CEvent>{...};
}

$(document).ready(function () {
 var response;
     $.ajax({
         type: 'POST',
         dataType: 'json',
         contentType: 'application/json',
         url: 'ProjectedYieldCalender.aspx/GetData',
         data: '{}',
         success:
                function (data) {
                    var eventList = data;
                    // OR var eventList = data.d
                    initCalendar(eventList);
                }

     });

function initCalendar(eventList){
    $('#calendar').fullCalendar({
        defaultDate: '2014-11-12',
        editable: true,
        eventLimit: true, // allow "more" link when too many events
        events: eventList
    });
}
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks. can you give me more clarity on events: eventList how to generate that above string in events
Nothing is displaying on web browser even the Calender if I do like you mention above.Please let me know where am I wrong?
$(document).ready(function () is not firing even if I place static content

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.