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

Radgrid won't refresh after failed update

1 Answer 90 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jonathan
Top achievements
Rank 1
Jonathan asked on 02 Apr 2012, 02:16 PM
I have a radgrid using advanced databinding to connect to a linq to sql datasource.  The grid allows the user to edit the data stored in a table in a sql database.  One of the fields is a foreign key to another table.  The grid will properly catch invalid values when editing a row and not allow the invalid value to be written to the database, however the invalid value still appears in the radgrid until the user clicks the grid's refresh button.  This is a problem because the user see's invalid values saved to the grid even though they are not saved to the database.

Here is the code behind for the update command
Protected Sub RadGrid1_UpdateCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.UpdateCommand
    Dim item As GridEditableItem = TryCast(e.Item, GridEditableItem)
    Dim ein = item.GetDataKeyValue("EIN").ToString()
    Dim distributor = DbContext.Distributors.Where(Function(n) n.EIN = ein).FirstOrDefault()
    item.UpdateValues(distributor)
    Dim channel = DbContext.Channels.Where(Function(n) n.ChannelId = distributor.ChannelId).FirstOrDefault()
    If channel Is Nothing Then
        displayError("Distributor was not updated. Please enter a valid channelId.")
        Else()
        Try
            DbContext.SubmitChanges()
        Catch ex As Exception
            displayError("Record cannot be updated")
 
        End Try
 
    End If
End Sub

The value that is causing the problem is the channelId.  I have written code to check if the channel exists and display a popup if the channel doesn't exist.  However, the grid still retains the invalid value.

Thanks in advance,
Jonathan Clark

1 Answer, 1 is accepted

Sort by
0
Jonathan
Top achievements
Rank 1
answered on 02 Apr 2012, 07:27 PM
If anyone reads this looking for help I found a solution that does what I need it to.

After displaying the message to the user to enter a valid value you can siimply cancel the event using "e.Canceled = True"

This has the result of leaving the grid in edit mode until the user either enters a valid value or presses cancel.

Hopefully this helps others.

-Jonathan
Tags
Grid
Asked by
Jonathan
Top achievements
Rank 1
Answers by
Jonathan
Top achievements
Rank 1
Share this question
or