Trying to use SessionDataSource

10 posts, 0 answers
  1. Cyrus
    Cyrus avatar
    52 posts
    Member since:
    Apr 2008

    Posted 24 Feb 2009 Link to this post

    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.

     

  2. Cyrus
    Cyrus avatar
    52 posts
    Member since:
    Apr 2008

    Posted 24 Feb 2009 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Yavor
    Admin
    Yavor avatar
    11 posts

    Posted 27 Feb 2009 Link to this post

    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.
  5. Cyrus
    Cyrus avatar
    52 posts
    Member since:
    Apr 2008

    Posted 02 Mar 2009 Link to this post

    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....
  6. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 03 Mar 2009 Link to this post

    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
  7. SuperXRAY
    SuperXRAY avatar
    82 posts
    Member since:
    Feb 2007

    Posted 12 Apr 2009 Link to this post

    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.
  8. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 13 Apr 2009 Link to this post

    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.
  9. SuperXRAY
    SuperXRAY avatar
    82 posts
    Member since:
    Feb 2007

    Posted 13 Apr 2009 Link to this post

    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 
  10. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 16 Apr 2009 Link to this post

    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.
  11. SuperXRAY
    SuperXRAY avatar
    82 posts
    Member since:
    Feb 2007

    Posted 16 Apr 2009 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017