How to bind separate date and time together in Start/End time fields?

6 posts, 2 answers
  1. Chan
    Chan avatar
    4 posts
    Member since:
    Nov 2011

    Posted 02 Dec 2011 Link to this post

    Hi, i m new in Telerik, i just starting to learn how to use the scheduler to create an appointment system.
    Actually my problem is: in my database, it used separate date("dd/mm/yyyy") and time("11/11/1766" hh:mm) to record the current appointment datetime, i cannot simply used Data Source Configuration Wizard to bind two separate data fields in each Start/End time fields, also, i am not allow to custom my database record format... is it anyway/possibility can bind two data in one single field? Or Radscheduler can make any custom setting to bind multiple data? Thx.
  2. Answer
    Ivana
    Admin
    Ivana avatar
    657 posts

    Posted 06 Dec 2011 Link to this post

    Hi Chan,

    You can create a new DataSet and merget the date and time fields. Here is an example:
    protected void Page_Load(object sender, EventArgs e)
       {
           SqlDataAdapter custAdapter = new SqlDataAdapter(@"SELECT * FROM [AppointmentTestTable]", @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Telerik.mdf;Integrated Security=True;User Instance=True");
     
           DataSet DS = new DataSet();
     
           custAdapter.Fill(DS, "AppointmentsTestTable");
     
         
           DataColumn start = default(DataColumn);
           DataColumn end = default(DataColumn);
     
     
           start = new DataColumn("Start", System.Type.GetType("System.DateTime"));
           end = new DataColumn("End", System.Type.GetType("System.DateTime"));
     
            
           DS.Tables["AppointmentsTestTable"].Columns.Add(start);
           DS.Tables["AppointmentsTestTable"].Columns.Add(end);
     
     
           foreach (DataRow dr in DS.Tables["AppointmentsTestTable"].Rows)
           {
               dr["Start"] = ((DateTime)dr["StartDate"]).Add((TimeSpan)dr["StartTime"]);
               dr["End"] = ((DateTime)dr["StartDate"]).Add((TimeSpan)dr["EndTime"]);
           }
     
           RadScheduler1.DataSource = DS;
           RadScheduler1.DataKeyField = "ID";
           RadScheduler1.DataSubjectField = "Subject";
           RadScheduler1.DataStartField = "Start";
           RadScheduler1.DataEndField = "End";
           RadScheduler1.DataBind();
       }

    Attached is a sample for reference.

    You can also take a look at the online documentation linked below, concerning RadScheduler's binding to a data source: RadScheduler Data binding.

    Binding two columns of a data base table to a single data container is rather unnecessary. The documentation linked above, explains in details the structure of a data base to which a RadScheduler control could be bound.

    The online populating with data demos of the RadScheduler, might be of help, too.

    All the best,
    Ivana
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Answer
    Pablo
    Pablo avatar
    10 posts
    Member since:
    Oct 2012

    Posted 06 Dec 2011 Link to this post

    Hi Chan,

    I'm assuming you are using SQL Server 2008 because you have two separate fields. What you can do is the following in your select query for the appointments where Start_Date & End_Date are a DATE datatype and End_Time & Start_Time are TIME datatype:

    SELECT (CAST(START_DATE AS DATETIME) + START_TIME) AS Start,  (CAST(END_DATE AS DATETIME) + END_TIME) AS End
    FROM YOUR_TABLE

    Thanks
      

  5. Ivana
    Admin
    Ivana avatar
    657 posts

    Posted 09 Dec 2011 Link to this post

    Hello Chan,

    Pablo is right, his suggestion is just another way to access the data from the data source and combine the two fields into one. I have modified the sample project; you could download it and try it locally.

    I hope this helps.

    Kind regards,
    Ivana
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
  6. Chan
    Chan avatar
    4 posts
    Member since:
    Nov 2011

    Posted 09 Dec 2011 Link to this post

    THX master Ivana and Pablo, it was great help to me!
  7. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 09 Dec 2011 Link to this post

    Hi Chan,

    Indeed, it will work, but you need to use this code:
    protected void Page_Load(object sender, EventArgs e)
        {
            SqlDataAdapter custAdapter = new SqlDataAdapter(@"SELECT CAST(StartDate AS DATETIME) + StartTime AS StartDate, Subject, ID, CAST(EndDate AS DATETIME) + EndTime AS EndDate
     FROM [AppointmentTestTable]", @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Telerik.mdf;Integrated Security=True;User Instance=True");
     
            DataSet DS = new DataSet();
     
            custAdapter.Fill(DS, "AppointmentsTestTable");
     
     
            RadScheduler1.DataSource = DS;
            RadScheduler1.DataKeyField = "ID";
            RadScheduler1.DataSubjectField = "Subject";
            RadScheduler1.DataStartField = "StartDate";
            RadScheduler1.DataEndField = "EndDate";
            RadScheduler1.DataBind();
        }



    Kind regards,
    Peter
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017