2011-08-31 115 views
1

我遇到了一些麻煩,我認爲,radSchedular。如何在更改綁定數據集後刷新radSchedule?

我有一個radSchedular我綁定到數據集。

我預計radSchedular時,我改變了數據集更新。但我不明白這一點。

我的問題是。數據集更新時如何更新radSchedular的顯示?

示例代碼:

我如何綁定: -

 private void BindToDataSet() 
    {     

     //Map fields for Appointments 
     AppointmentMappingInfo appointmentMappingInfo = new AppointmentMappingInfo(); 

     appointmentMappingInfo.Start = "appointments_Start"; 
     appointmentMappingInfo.End = "appointments_End";  //LOTS OF THESE SO I CUT THE REST OUT OF THIS EXAMPLE 


     datasource.EventProvider.Mapping = appointmentMappingInfo; 
     datasource.EventProvider.DataSource = dsSchedule.Tables[0]; //MY DATASET IS GENERATED FROM AN XML FILE WITH A SCHEMA 

     //Bind 
     radScheduler1.DataSource = datasource; 
    } 

我如何獲得數據集改變事件: -

private void BindEvents(){ 
// RowChanged event handler. 
dsSchedule.Tables[0].RowChanged += new DataRowChangeEventHandler(RowChanged); 

// Add a RowDeleted event handler. 
dsSchedule.Tables[0].RowDeleted += new DataRowChangeEventHandler(RowDeleted);} 

事件方法: -

private void RowChanged(object sender, DataRowChangeEventArgs e){ 
StoreToXML(); 
BindEvents();} 

我如何存儲數據a第二,我想,刷新radSchedular: -

private void StoreToXML(){ 

//remove the dataset change deligates as we are about to change the Dataset and we don't want a loop 
UnBindEvents(); 

foreach (DataRow rowAppointments in dsSchedule.Tables["Appointments"].Rows) 
{ 
    string currentResource = rowAppointments["appointments_ResourceID"].ToString(); 

    foreach (DataRow rowResources in dsSchedule.Tables["Resources"].Rows) 
    { 
    if (rowResources["resources_ID"].ToString() == currentResource) 
    { 
     rowAppointments["appointments_Location"] = rowResources["resources_Name"]; //THIS IS WHY I WANT THE radSCHEDULAR TO UPDATE. 
    }          //I WANT TO SEE THE RESOURCE IN THE LOCATION FIELD 
    } 
} 


StreamWriter myStreamWriter = new StreamWriter(@"E:\My .NET\Hardware_Scheduler_Application\stdData.xml"); 
dsSchedule.WriteXml(myStreamWriter, XmlWriteMode.WriteSchema); 
myStreamWriter.Close(); 
BindToDataSet(); //I THOUGHT THAT THIS WOULD REFRESH THE radSCHEDULAR 

//rebind the changed events 
BindEvents()} 
+0

數據集是否暴露IObservable? –

+0

不,我不認爲DataSets可以。 – Richard210363

回答

0

我能夠把下面這兩行代碼在事件RadScheduler1_AppointmentInsertRadScheduler1_AppointmentDelete月底解決這一問題我自己。這兩條線是:

Appointments.Clear(); 
InitializeAppointments(); 

這將只適用於您,如果您按照Telerik網站上給出的示例設置您的網格。你可以在這裏找到鏈接:https://demos.telerik.com/aspnet-ajax/scheduler/examples/overview/defaultcs.aspx

相關問題