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

Datasource in code-behind

4 Answers 243 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Nice2
Top achievements
Rank 1
Nice2 asked on 26 Aug 2008, 08:53 AM
Hello,

I am currently testing out the RADcontrols and specificaly the scheduler at the moment.

I always much rather set my datasources in the code-behind and tried so.

This is what my front code looks like:

  <telerik:RadScheduler runat="server" ID="radAfspraken" 
            Width="900px" Skin="Sunset" EnableEmbeddedSkins="True" SelectedView="DayView" GroupBy="Plaats" GroupingDirection="Horizontal" 
            DayStartTime="08:00:00" DayEndTime="19:00:00" TimeZoneOffset="03:00:00" 
            DataKeyField="ID" DataSubjectField="Omschrijving" 
            DataStartField="Start" DataEndField="Eind" DataRecurrenceField="Herhalingsregel" 
            DataRecurrenceParentKeyField="HerhalingsID">  
              
            <TimelineView UserSelectable="false" /> 
             
        </telerik:RadScheduler> 

and here is my code-behind:

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load  
        Dim sdsA As SessionDataSource  
        sdsA = New SessionDataSource  
        sdsA.ID = "sdsAfspraak" 
        sdsA.DisplayWarning = False 
        sdsA.PrimaryKeyFields = "ID" 
        sdsA.ProviderName = "System.Data.SqlClient" 
        sdsA.ConnectionString = ConfigurationManager.ConnectionStrings("UrenPortal").ConnectionString  
        sdsA.SelectCommand = "Select ID, omschrijving, start, eind, plaatsID, herhalingsregel, herhalingsID FROM afspraken" 
        sdsA.InsertCommand = "INSERT INTO afspraken (omschrijving, start, eind, PlaatsID, herhalingsregel, herhalingsID) VALUES (@Omschrijving, @Start, @Eind, @PlaatsID, @Herhalingsregel, @HerhalingsID)" 
        sdsA.UpdateCommand = "UPDATE afspraken SET omschrijving = @Omschrijving, start = @Start, eind = @Eind, PlaatsID = @PlaatsID, Herhalingsregel = @Herhalingsregel, HerhalingsID = @HerhalingsID WHERE ID = @ID" 
        sdsA.DeleteCommand = "DELETE FROM afspraken WHERE ID = @ID" 
        sdsA.DeleteParameters.Add(New Parameter("ID", TypeCode.Int32))  
 
        sdsA.UpdateParameters.Add(New Parameter("ID", TypeCode.Int32))  
        sdsA.UpdateParameters.Add(New Parameter("omschrijving", TypeCode.String))  
        sdsA.UpdateParameters.Add(New Parameter("start", TypeCode.DateTime))  
        sdsA.UpdateParameters.Add(New Parameter("eind", TypeCode.DateTime))  
        sdsA.UpdateParameters.Add(New Parameter("plaatsID", TypeCode.Int32))  
        sdsA.UpdateParameters.Add(New Parameter("herhalingsregel", TypeCode.String))  
        sdsA.UpdateParameters.Add(New Parameter("herhalingsID", TypeCode.Int32))  
 
        sdsA.InsertParameters.Add(New Parameter("omschrijving", TypeCode.String))  
        sdsA.InsertParameters.Add(New Parameter("start", TypeCode.DateTime))  
        sdsA.InsertParameters.Add(New Parameter("eind", TypeCode.DateTime))  
        sdsA.InsertParameters.Add(New Parameter("plaatsID", TypeCode.Int32))  
        sdsA.InsertParameters.Add(New Parameter("herhalingsregel", TypeCode.String))  
        sdsA.InsertParameters.Add(New Parameter("herhalingsID", TypeCode.Int32))  
 
        radAfspraken.DataSource = sdsA 
 
        Dim sdsP As SessionDataSource  
        sdsP = New SessionDataSource  
        sdsP.ID = "sdsPlaats" 
        sdsP.DisplayWarning = False 
        sdsP.ConnectionString = ConfigurationManager.ConnectionStrings("UrenPortal").ConnectionString  
        sdsP.ProviderName = "System.Data.SqlClient" 
        sdsP.SelectCommand = "SELECT PlaatsID, Naam FROM plaatsen" 
 
        Dim rtPlaats As New ResourceType  
        rtPlaats.KeyField = "PlaatsID" 
        rtPlaats.Name = "Plaats" 
        rtPlaats.TextField = "Naam" 
        rtPlaats.ForeignKeyField = "PlaatsID" 
        rtPlaats.DataSource = sdsP 
        radAfspraken.ResourceTypes.Add(rtPlaats)  
 
 
    End Sub 


It uses the template from the example shown here:

http://www.telerik.com/demos/aspnet/prometheus/Scheduler/Examples/ResourceGrouping/DefaultCS.aspx

Now I also added the SessionDataSource.cs in my app_code and I have no build errors. Still I am receiving an error in my SessionDataSource.cs:

Object not set to a reference of an object (I get the dutch version so sorry if my translation isn't 100% correct)

The error occurs on line:

181:                return (string) ViewState["SessionKey"] ?? Page.ToString() + "_" + ID;  
 

in SessionDataSource.cs

Any idea what I am doing wrong?

Thanks in advance!

4 Answers, 1 is accepted

Sort by
0
Accepted
Dimitar Milushev
Telerik team
answered on 26 Aug 2008, 12:29 PM
Hello Nice2,

You need to add the two SessionDataSources, sdsA and sdsP to the Controls collection of the Page e.g.:

        sdsA = New SessionDataSource
        Controls.Add(sdsA)

Please note that the SessionDataSource is a special DataSource designed to be used in our demos. It is designed in way that any changes to the Data are saved only for the current session and is not usable in real-life scenarios.

Greetings,
Dimitar Milushev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Nice2
Top achievements
Rank 1
answered on 26 Aug 2008, 12:53 PM
Thanks for the information.

I'll just make a dataset then as datasource.
0
Ganso
Top achievements
Rank 1
answered on 02 Dec 2008, 05:37 AM
Hi, what is the SessionDataSource? can't found much documentation about it, i'm trying to replicate the example in http://demos.telerik.com/ASPNET/Prometheus/ComboBox/Examples/Functionality/AutoCompleteClientSide/DefaultCS.aspx.

thanks!
0
Dimitar Milushev
Telerik team
answered on 02 Dec 2008, 06:21 AM
Hi Ganso,

The SessionDataSource is a simple DataSource created to be used in our demos. It temporarily persists data in the Session to show how the controls are used with a DataSource, but once you reload the page the data is reset. It is not intended for real-life scenarios, but you can replicate the same functionality with any DataSource, for example SqlDataSource.

Kind regards,
Dimitar Milushev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Scheduler
Asked by
Nice2
Top achievements
Rank 1
Answers by
Dimitar Milushev
Telerik team
Nice2
Top achievements
Rank 1
Ganso
Top achievements
Rank 1
Share this question
or