How to Resolve Jason issue

Posted by Mohammad Nezhad on Stack Overflow See other posts from Stack Overflow or by Mohammad Nezhad
Published on 2010-04-08T06:48:22Z Indexed on 2010/04/08 6:53 UTC
Read the original article Hit count: 823

Filed under:
|

I am working in a web scheduling application which uses DayPilot component

I started by reading the documentation and use the calendar control. but whenever I do some thing which (fires an event on the Daypilot control) I face with following error

     An exception was thrown in the server-side event handler:

     System.InvalidCastException: Instance Of JasonData doesn't hold a double
     at DayPilot.Jason.JasonData.op_Explicit(JasonData data)
     at DayPilot.Web.Ui.Events.EventMoveEventArgs..ctor(JasonData parameters, string[] fields, JasonData data)
     at DayPilot.Web.Ui.DayPilotCalendar.ExecuteEventJASON(String ea)
     at DayPilot.Web.Ui.DayPilotCalendar.System.Web.UI.ICallbackEventHandler.RaiseCallbackEvent(string ea)
     at System.Web.UI.Page.PrepareCallback(String callbackControlID)

here is the completed code in the ASPX page

    <DayPilot:DayPilotCalendar ID="DayPilotCalendar1" runat="server" 
        Direction="RTL" Days="7"
          DataStartField="eventstart" DataEndField="eventend" DataTextField="name" 
        DataValueField="id" DataTagFields="State"
          EventMoveHandling="CallBack"
          OnEventMove="DayPilotCalendar1_EventMove"

EventEditHandling="CallBack" OnEventEdit="DayPilotCalendar1_EventEdit" EventClickHandling="Edit" OnBeforeEventRender="DayPilotCalendar1_BeforeEventRender" EventResizeHandling="CallBack" OnEventResize="DayPilotCalendar1_EventResize" EventDoubleClickHandling="CallBack" OnEventDoubleClick="DayPilotCalendar1_EventDoubleClick" oncommand="DayPilotCalendar1_Command" >

and here is the complete codebehind

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            Initialization();
    }

    private void dbUpdateEvent(string id, DateTime start, DateTime end) 
    {   // update for move
        using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["db"].ConnectionString))
        {
            con.Open();
            SqlCommand cmd = new SqlCommand("UPDATE [event] SET [eventstart] = @start, [eventend] = @end WHERE [id] = @id", con);
            cmd.Parameters.AddWithValue("id", id);
            cmd.Parameters.AddWithValue("start", start);
            cmd.Parameters.AddWithValue("end", end);
            cmd.ExecuteNonQuery();
        }
    }

    private DataTable dbGetEvents(DateTime start, int days)
    {   // get Data
        SqlDataAdapter da = new SqlDataAdapter("SELECT [id], [name], [eventstart], [eventend], [state], [other] FROM [event] WHERE NOT (([eventend] <= @start) OR ([eventstart] >= @end))", ConfigurationManager.ConnectionStrings["DayPilotTest"].ConnectionString); ;
        da.SelectCommand.Parameters.AddWithValue("start", start);
        da.SelectCommand.Parameters.AddWithValue("end", start.AddDays(days));
        DataTable dt = new DataTable();
        da.Fill(dt);
        return dt;
    }

    protected void DayPilotCalendar1_EventMove(object sender, DayPilot.Web.Ui.Events.EventMoveEventArgs e)
    {   // Drag and Drop
        dbUpdateEvent(e.Value, e.NewStart, e.NewEnd);
        DayPilotCalendar1.DataSource = dbGetEvents(DayPilotCalendar1.StartDate, DayPilotCalendar1.Days);
        DayPilotCalendar1.DataBind();
        DayPilotCalendar1.Update();
    }

    private void Initialization()
    {   // first bind
        DayPilotCalendar1.StartDate = DayPilot.Utils.Week.FirstDayOfWeek(new DateTime(2009, 1, 1));
        DayPilotCalendar1.DataSource = dbGetEvents(DayPilotCalendar1.StartDate, DayPilotCalendar1.Days);
        DataBind();
    }

    protected void DayPilotCalendar1_BeforeEventRender(object sender, BeforeEventRenderEventArgs e)
    {   // change the color based on state
        if (e.Tag["State"] == "Fixed")
        {
            e.DurationBarColor = "Brown";
        }
    }

    protected void DayPilotCalendar1_EventResize(object sender, DayPilot.Web.Ui.Events.EventResizeEventArgs e)
    {
        dbUpdateEvent(e.Value, e.NewStart, e.NewEnd);
        DayPilotCalendar1.DataSource = dbGetEvents(DayPilotCalendar1.StartDate, DayPilotCalendar1.Days);
        DayPilotCalendar1.DataBind();
        DayPilotCalendar1.Update();
    }

    protected void DayPilotCalendar1_EventDoubleClick(object sender, EventClickEventArgs e)
    {
        dbInsertEvent(e.Text , e.Start, e.End, "New", "New Meeting");
        DayPilotCalendar1.DataSource = dbGetEvents(DayPilotCalendar1.StartDate, DayPilotCalendar1.Days);
        DayPilotCalendar1.DataBind();
        DayPilotCalendar1.Update();
    }

note that I remove unnecessary code behinds

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET