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

Trying to use SessionDataSource

9 Answers 240 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Cyrus
Top achievements
Rank 1
Cyrus asked on 24 Feb 2009, 11:42 PM
I am trying to use the SessionDataSource.dll for a project where I do not want to store data.  however, I am having difficulties trying to make this work.  I can connect to the data source and insert data into the grid but I am not getting an ID to populate.  This makes it impossible to reference the row for an update or delete function.  Any idea what I am doing wrong?  I have an access database which uses a field called ID with a data type auto-increment.  The table is blank and has no data, the only thing it has is columns with headers.

 

9 Answers, 1 is accepted

Sort by
0
Cyrus
Top achievements
Rank 1
answered on 25 Feb 2009, 04:17 AM
I figured it out, I was missing the parameter PrimaryKeyFields="ID"

Could you guys provide this data source as a supported and outlined feature?  I think its a neat thing to have and should be a released part of your code.
0
Yavor
Telerik team
answered on 27 Feb 2009, 01:03 PM
Hello Cyrus,

Basically, this datasource is used for demonstrative purposes only, and we do not want to promote it, or push its usage. On the contrary, in the latest releases we are reducing the usage of this particular datasource, and use standard controls.

Kind regards,
Yavor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Cyrus
Top achievements
Rank 1
answered on 02 Mar 2009, 11:34 PM
How would you create a temporary data source for a demo form?  Do you have other suggestions?  I need to create a form that doesn't save data but has all the behaviors of a datagrid/radgrid.  This seemed to be the answer, but I am finding some bizarre behavior in FireFox.  Not entirely sure it is the SessionDataSource....
0
Shinu
Top achievements
Rank 2
answered on 03 Mar 2009, 06:09 AM
Hi Cyrus,

I would suggest you to try the logic used in the following online demo where the changes during the Insert/Update/Delete operation is being made on the DataTable and it is not affecting the DataBase. Hence all the changes made will be reflected temporarily in the Grid.
User control edit form

Thanks
Shinu
0
SuperXRAY
Top achievements
Rank 2
answered on 13 Apr 2009, 03:33 AM
Shinu,

Thank you. However, I modified the files from that link to use a datatable that is completely in session. There is no SQL Connection going on. My problem is that the RadGrid never leaves Insert mode, even though a row is inserted and the grid displays it. Also, when I update a row, that row stays in Edit mode, and the data DOES get changed, because I can cancel and refresh, things are fine.

I had to add RadGrid1.ReBind() at the end of the Update/Insert/Delete events to get the data refreshed in the grid.

Any ideas? I am NOT using a User Control Edit Form, I modified the code to use the standard in-place editing.
0
Iana Tsolova
Telerik team
answered on 13 Apr 2009, 07:00 AM
Hi,

You could close the edit and insert grid items as shown below, before the grid is rebound:

C#
RadGrid1.EditedIndexes.Clear(); //this is fir the edited items  
RadGrid1.MasterTableView.IsItemInserted = false//this is for the insert item  
RadGrid1.Rebind(); 

Find more information here.

Best wishes,
Iana
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
SuperXRAY
Top achievements
Rank 2
answered on 13 Apr 2009, 03:59 PM
Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: Insert item is available only when grid is in insert mode.

That's the error I get when I insert the corrected code, as EditedIndexes is actually EditIndexes. Here's my entire function:

Protected Sub RadGrid1_InsertCommand(ByVal source As ObjectByVal e As GridCommandEventArgs) Handles RadGrid1.InsertCommand  
        If (TypeOf e.Item Is GridDataInsertItem) AndAlso (e.Item.OwnerTableView.IsItemInserted) Then 
            Dim insertItem As GridDataInsertItem = DirectCast(e.Item, GridDataInsertItem)  
            Dim rcb As RadComboBox = DirectCast(insertItem("Option").Controls(0), RadComboBox)  
            Dim txtComments As TextBox = DirectCast(insertItem("Comments").Controls(0), TextBox)  
            Dim optionId As Integer = rcb.SelectedValue  
            Dim comments As String = txtComments.Text  
 
            'Create new row in the DataSource  
            Dim newRow As DataRow = Me.VehicleOptionsTable.NewRow()  
 
            'Insert new values  
            Dim newValues As New Hashtable()  
            newValues("Id") = Guid.NewGuid()  
            newValues("OptionId") = optionId  
            newValues("Comments") = comments  
 
            Try 
                For Each entry As DictionaryEntry In newValues  
                    newRow(DirectCast(entry.Key, String)) = entry.Value  
                Next 
                Me.VehicleOptionsTable.Rows.Add(newRow)  
                Me.VehicleOptionsTable.AcceptChanges()  
 
            Catch ex As Exception  
                Dim lblError As New Label()  
                lblError.Text = "Unable to insert Option. Reason: " + ex.Message  
                lblError.ForeColor = System.Drawing.Color.Red  
                RadGrid1.Controls.Add(lblError)  
 
                e.Canceled = True 
            End Try 
 
        End If 
 
        RadGrid1.EditIndexes.Clear()  
        RadGrid1.MasterTableView.IsItemInserted = False 
        RadGrid1.Rebind()  
 
    End Sub 
0
Iana Tsolova
Telerik team
answered on 16 Apr 2009, 07:34 AM
Hi SuperXRAY,

First, excuse me for misleading you with the wrong property name.

Please try applying the below slight changes to the InsertCommand event handler and let me know if it works this way:

Protected Sub RadGrid1_InsertCommand(ByVal source As ObjectByVal e As GridCommandEventArgs) Handles RadGrid1.InsertCommand     
        If (TypeOf e.Item Is GridDataInsertItem) AndAlso (e.Item.OwnerTableView.IsItemInserted) Then    
            Dim insertItem As GridDataInsertItem = DirectCast(e.Item, GridDataInsertItem)     
            Dim rcb As RadComboBox = DirectCast(insertItem("Option").Controls(0), RadComboBox)     
            Dim txtComments As TextBox = DirectCast(insertItem("Comments").Controls(0), TextBox)     
            Dim optionId As Integer = rcb.SelectedValue     
            Dim comments As String = txtComments.Text     
    
            'Create new row in the DataSource     
            Dim newRow As DataRow = Me.VehicleOptionsTable.NewRow()     
    
            'Insert new values     
            Dim newValues As New Hashtable()     
            newValues("Id") = Guid.NewGuid()     
            newValues("OptionId") = optionId     
            newValues("Comments") = comments     
    
            Try    
                For Each entry As DictionaryEntry In newValues     
                    newRow(DirectCast(entry.Key, String)) = entry.Value     
                Next    
                Me.VehicleOptionsTable.Rows.Add(newRow)     
                Me.VehicleOptionsTable.AcceptChanges()     
    
            Catch ex As Exception     
                Dim lblError As New Label()     
                lblError.Text = "Unable to insert Option. Reason: " + ex.Message     
                lblError.ForeColor = System.Drawing.Color.Red     
                RadGrid1.Controls.Add(lblError)     
    
                e.Canceled = True    
            End Try    
    
        End If    
      
        e.Canceled = True 
        RadGrid1.MasterTableView.IsItemInserted = False    
        RadGrid1.Rebind()     
    
    End Sub   


All the best,
Iana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
SuperXRAY
Top achievements
Rank 2
answered on 16 Apr 2009, 08:29 AM
Actually, my grid happened to be in Automatic Insert/Update/delete mode. Changing it out solved my problem and I removed all of the clearing code.

Thanks for replying, though.
Tags
Grid
Asked by
Cyrus
Top achievements
Rank 1
Answers by
Cyrus
Top achievements
Rank 1
Yavor
Telerik team
Shinu
Top achievements
Rank 2
SuperXRAY
Top achievements
Rank 2
Iana Tsolova
Telerik team
Share this question
or