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

Databinding issue from datatable

2 Answers 219 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
vineet
Top achievements
Rank 1
vineet asked on 28 Feb 2018, 12:20 PM

I am binding the data from a datatable but it is always binding the data against the current date.If i have set the selected date is something else also.

 

 

Code

using System;
using System.Text;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    { 
        if(!Page.IsPostBack)
        {
            dtpDate.SelectedDate = DateTime.Today.AddDays(0);
        //    OTTable();
        }
     
        //RadScheduler1.SelectedDate = (DateTime.Today.AddDays(2));
    }
    private void OTTable()
    {
        RadScheduler1.DataSource = null;
        RadScheduler1.DataBind();
        // Create a new Data Table.
        System.Data.DataTable OTTheater = new DataTable("OTTheater");
        DataColumn dtColumn;
        DataRow myDataRow;
        // Create id Column
        dtColumn = new DataColumn();
        dtColumn.DataType = System.Type.GetType("System.Int32");
        dtColumn.ColumnName = "TheaterId";
        dtColumn.Caption = "TheaterId";
        dtColumn.ReadOnly = false;
        dtColumn.Unique = true;
        // Add id column to the DataColumnCollection.
        OTTheater.Columns.Add(dtColumn);

        // create Name column.
        dtColumn = new DataColumn();
        dtColumn.DataType = System.Type.GetType("System.String");
        dtColumn.ColumnName = "TheatreName";
        dtColumn.Caption = "TheatreName";
        dtColumn.AutoIncrement = false;
        dtColumn.ReadOnly = false;
        dtColumn.Unique = false;

        // Add Address column to the table.
        OTTheater.Columns.Add(dtColumn);

        
        
        // Add rows to the custTable using NewRow method
        // I add three customers with their addresses, name and id
        myDataRow = OTTheater.NewRow();
        myDataRow["TheaterId"] = 1;
        myDataRow["TheatreName"] = "OT1";
        
        OTTheater.Rows.Add(myDataRow);

        myDataRow = OTTheater.NewRow();
        myDataRow["TheaterId"] = 2;
        myDataRow["TheatreName"] = "OT2";
        
        OTTheater.Rows.Add(myDataRow);


        System.Data.DataTable OTPatientDetail = new DataTable("OTPatientDetail");
        DataColumn dtOTPatientDetailn;
        DataRow myDataRowOTPatientDetail;
        // Create id Column
        dtOTPatientDetailn = new DataColumn();
        dtOTPatientDetailn.DataType = System.Type.GetType("System.Int32");
        dtOTPatientDetailn.ColumnName = "TheaterId";
        dtOTPatientDetailn.Caption = "TheaterId";
        dtOTPatientDetailn.ReadOnly = false;
        //dtOTPatientDetailn.Unique = true;
        // Add id column to the DataColumnCollection.
        OTPatientDetail.Columns.Add(dtOTPatientDetailn);

        dtOTPatientDetailn = new DataColumn();
        dtOTPatientDetailn.DataType = System.Type.GetType("System.String");
        dtOTPatientDetailn.ColumnName = "TheatreName";
        dtOTPatientDetailn.Caption = "TheatreName";
        dtOTPatientDetailn.ReadOnly = false;
        //dtOTPatientDetailn.Unique = true;
        // Add id column to the DataColumnCollection.
        OTPatientDetail.Columns.Add(dtOTPatientDetailn);


        dtOTPatientDetailn = new DataColumn();
        dtOTPatientDetailn.DataType = System.Type.GetType("System.String");
        dtOTPatientDetailn.ColumnName = "FromTime";
        dtOTPatientDetailn.Caption = "FromTime";
        dtOTPatientDetailn.ReadOnly = false;
        //dtOTPatientDetailn.Unique = true;
        // Add id column to the DataColumnCollection.
        OTPatientDetail.Columns.Add(dtOTPatientDetailn);

        dtOTPatientDetailn = new DataColumn();
        dtOTPatientDetailn.DataType = System.Type.GetType("System.String");
        dtOTPatientDetailn.ColumnName = "ToTime";
        dtOTPatientDetailn.Caption = "ToTime";
        dtOTPatientDetailn.ReadOnly = false;
        //dtOTPatientDetailn.Unique = true;
        // Add id column to the DataColumnCollection.
        OTPatientDetail.Columns.Add(dtOTPatientDetailn);

        dtOTPatientDetailn = new DataColumn();
        dtOTPatientDetailn.DataType = System.Type.GetType("System.String");
        dtOTPatientDetailn.ColumnName = "Subject";
        dtOTPatientDetailn.Caption = "Subject";
        dtOTPatientDetailn.ReadOnly = false;
        //dtOTPatientDetailn.Unique = true;
        // Add id column to the DataColumnCollection.
        OTPatientDetail.Columns.Add(dtOTPatientDetailn);

        dtOTPatientDetailn = new DataColumn();
        dtOTPatientDetailn.DataType = System.Type.GetType("System.String");
        dtOTPatientDetailn.ColumnName = "TooTipText";
        dtOTPatientDetailn.Caption = "TooTipText";
        dtOTPatientDetailn.ReadOnly = false;
        //dtOTPatientDetailn.Unique = true;
        // Add id column to the DataColumnCollection.
        OTPatientDetail.Columns.Add(dtOTPatientDetailn);


       


        //TheaterId, TheaterName, FromTime, ToTime, Subject, TooTipText

        myDataRowOTPatientDetail = OTPatientDetail.NewRow();
        myDataRowOTPatientDetail["TheaterId"] = 1;
        myDataRowOTPatientDetail["TheatreName"] = "OT1";
        myDataRowOTPatientDetail["FromTime"] = "10:00";
        myDataRowOTPatientDetail["ToTime"] = "11:00";
        myDataRowOTPatientDetail["Subject"] = "Test Patient";
        myDataRowOTPatientDetail["TooTipText"] = "Test Patient";
     
        OTPatientDetail.Rows.Add(myDataRowOTPatientDetail);

        myDataRowOTPatientDetail = OTPatientDetail.NewRow();
        myDataRowOTPatientDetail["TheaterId"] = 2;
        myDataRowOTPatientDetail["TheatreName"] = "OT2";
        myDataRowOTPatientDetail["FromTime"] = "09:00";
        myDataRowOTPatientDetail["ToTime"] = "11:00";
        myDataRowOTPatientDetail["Subject"] = "Test Patient";
        myDataRowOTPatientDetail["TooTipText"] = "Test Patient";
        
        OTPatientDetail.Rows.Add(myDataRowOTPatientDetail);





 
        DataTable Dt = new DataTable();

   
        RadScheduler1.SelectedView = SchedulerViewType.DayView;
        RadScheduler1.SelectedDate = dtpDate.SelectedDate.Value;
        RadScheduler1.WorkDayStartTime = TimeSpan.Parse("06:00");
        RadScheduler1.WorkDayEndTime = TimeSpan.Parse("00:00");

        RadScheduler1.DayStartTime = TimeSpan.Parse("08:00");
        RadScheduler1.DayEndTime = TimeSpan.Parse("00:00");
       
        RadScheduler1.MinutesPerRow = int.Parse("10");
        //RadScheduler1.TimeLabelRowSpan = 30 / int.Parse(OTPatientDetail.Rows[0]["ToTime"].ToString());
      
        RadScheduler1.DataKeyField = "TheaterId";
        RadScheduler1.DataStartField = "FromTime";
        RadScheduler1.DataEndField = "ToTime";
        RadScheduler1.DataSubjectField = "Subject";

        //RadScheduler1.GroupBy = "Resource";
        //RadScheduler1.DataRecurrenceField = "RecurrenceRule";
        //RadScheduler1.DataRecurrenceParentKeyField = "RecurrenceParentId";
        RadScheduler1.ResourceTypes.Clear();
        ResourceType rt = new ResourceType("Resource");
        rt.DataSource = OTTheater;
        rt.KeyField = "TheaterId";
        rt.ForeignKeyField = "TheaterId";
        rt.TextField = "TheatreName";
        RadScheduler1.ResourceTypes.Add(rt);
       
        RadScheduler1.DataSource = OTPatientDetail;
        RadScheduler1.DataBind();
        
    }


    protected void RadScheduler1_AppointmentDataBound(object sender, SchedulerEventArgs e)
    {
        e.Appointment.ToolTip = e.Appointment.Attributes["TooTipText"];
    }

    protected void RadScheduler1_AppointmentCreated(object sender, AppointmentCreatedEventArgs e)
    {
        WebControl rsAptInner = (WebControl)e.Container.Parent;
        rsAptInner.Style["background"] = "#4286f4";
    }

    protected void RadScheduler1_TimeSlotContextMenuItemClicked(object sender, TimeSlotContextMenuItemClickedEventArgs e)
    {

    }

    protected void RadScheduler1_AppointmentContextMenuItemClicked(object sender, AppointmentContextMenuItemClickedEventArgs e)
    {

    }

    protected void RadScheduler1_NavigationCommand(object sender, SchedulerNavigationCommandEventArgs e)
    {

    }

    protected void RadScheduler1_TimeSlotCreated(object sender, TimeSlotCreatedEventArgs e)
    {

    }

    protected void as_Click(object sender, EventArgs e)
    {
       
        OTTable();
    }
    protected void OnSelectedDateChanged_dtpDate(object sender, EventArgs e)
    {
        try
        {

            as_Click(sender, e);
        }
        catch (Exception Ex)
        {
           
        }
    }
}

2 Answers, 1 is accepted

Sort by
0
vineet
Top achievements
Rank 1
answered on 02 Mar 2018, 03:09 PM
I am still facing the same issue please somebody help
0
Peter Milchev
Telerik team
answered on 05 Mar 2018, 10:23 AM
Hello Vineet,

We created a sample project based on the provided code snippets and with few adjustments, it is working correctly now. Attached are the sample project and a screencast demonstrating its behavior.

Changes are: 
  • DataBinding setting the DataSource on every postback;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            dtpDate.SelectedDate = DateTime.Today.AddDays(0);
        }
     
        OTTable();
     
        //RadScheduler1.SelectedDate = (DateTime.Today.AddDays(2));
    }
  • Remove initial binding to null in the OTTable method:
    private void OTTable()
    {
        // Commented the following 2 rows
        //RadScheduler1.DataSource = null;
        //RadScheduler1.DataBind();
        // Create a new Data Table.
        System.Data.DataTable OTTheater = new DataTable("OTTheater");
         
        // populating DataTable code here.
     
        RadScheduler1.DataSource = OTPatientDetail;
        // Commented the following row
        //RadScheduler1.DataBind();
     
    }

More information on using the DataSource property can be found here: https://docs.telerik.com/devtools/aspnet-ajax/controls/scheduler/data-binding/using-the-data-source-property

If that is not the desired behavior, please provide more details and specific examples of the current and actual behavior along with details on the exact reproduction steps.

Regards,
Peter Milchev
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Scheduler
Asked by
vineet
Top achievements
Rank 1
Answers by
vineet
Top achievements
Rank 1
Peter Milchev
Telerik team
Share this question
or