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

Edit makes GridBinaryImageColumn null!

2 Answers 192 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Darren
Top achievements
Rank 2
Darren asked on 30 Sep 2009, 02:33 PM
Hi,

I have a Radgrid and using a telerik:GridBinaryImageColumn.
I've hooked up the Radgrid to a SqlDataSource allowing Automatic INSERTS/UPDATES/DELETES.
My table has a column "Logo" which is of "image" type and allows nulls.

If I create a record and upload an image everything is fine. But when I click update and update a different field for example "name", then the image gets deleted because I never selected one! So every time I update I have to select an image, and I'm sure you can see that that is a problem.

Any help would be great thanks.
Darren

2 Answers, 1 is accepted

Sort by
0
Accepted
Tsvetoslav
Telerik team
answered on 05 Oct 2009, 05:41 AM
Hi Darren,

The behavior you are experiencing is expected as the grid is storing into the database the binary data of the image - not its path. Hence, when you open the edit form there is no way for the grid control to automatically populate the upload text box with the path to the image all the more as this path might have changed meanwhile. On the other hand, it is not reasonable for the grid to cache the old binary data so that if you do not choose a file to upload it will send the old binary to the data store. The reasonable and logical way to implement your scenario is to check if the user has selected a file to upload or not and change the update command of the data source control accordingly. The attached sample demonstrates an easy way to achieve that.

Greetings,
Tsvetoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Can
Top achievements
Rank 1
answered on 08 Apr 2011, 06:22 PM
For the vb version:

Protected Sub RadGrid1_UpdateCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.UpdateCommand
        If e.CommandName = "Update" Then
            Dim item As GridEditableItem = e.Item
            Dim uploadControl As RadUpload = item("Upload").Controls(0)
            If (uploadControl.UploadedFiles.Count > 0) Then
                ImagePath = uploadControl.UploadedFiles(0).FileName
            End If
        End If
    End Sub

Protected Sub SqlDataSource1_Updating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs) Handles SqlDataSource1.Updating
        If ImagePath = String.Empty Then
            e.Command.CommandText = "UPDATE table SET name = @name WHERE id = @id"
        Else
            e.Command.CommandText = "UPDATE table SET name = @name, photo = @photo WHERE id = @id"
        End If
    End Sub
Tags
Grid
Asked by
Darren
Top achievements
Rank 2
Answers by
Tsvetoslav
Telerik team
Can
Top achievements
Rank 1
Share this question
or