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?
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
});
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.