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

RadBinaryImage DataValue null inside Dataform

2 Answers 135 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
Riad
Top achievements
Rank 1
Riad asked on 12 Jan 2015, 05:50 PM
Hi, I use the RadDataform to manage some company news within my application. (NewsData object - )

I was able to manage the addition of a RadAsyncUpload in the ItemInsertTemplate mixed with a RadBinaryImage.
When the user upload an image, a preview of the image is shown by the BinaryImage (using this example http://demos.telerik.com/aspnet-ajax/imageeditor/examples/imageupload/defaultcs.aspx?product=asyncupload)

Using the RadDataForm, I went with the manual CRUD approch. I read your article about the manual CRUD using the _ItemInserting method.
So my code is

protected void RadDataForm1_ItemInserting(object sender, RadDataFormCommandEventArgs e)
    {
        RadDataFormInsertItem insertedItem = e.DataFormItem as RadDataFormInsertItem;
        Hashtable newValues = new Hashtable();
        insertedItem.ExtractValues(newValues);
 
        RPKNewsData test = new RPKNewsData(newValues);
        test.Save();
    }

This is my code when the ImageUploadEvent is raised on the server side when the user upload an image.
protected void Test2_FileUploaded(object sender, FileUploadedEventArgs e)
    {
        RadDataFormEditableItem editItem = ((Telerik.Web.UI.RadWebControl)(sender)).NamingContainer as RadDataFormEditableItem;
        RadBinaryImage bImg = editItem.FindControl("RadBinaryImage1") as RadBinaryImage;
        byte[] image;
        long fileLength = e.File.InputStream.Length;
        image = new byte[fileLength];
        e.File.InputStream.Read(image, 0, image.Length);
        bImg.DataValue = image;
    }

My problem is: the Image key in my hashtable is null. But all the other properties are filled correctly according to my Business object. 
I even tried to browse RadDataForm1.FindControl("RadBinaryImage1") and the binaryimage is set to an URL.

Is there a way to get the binary data of the image so i can save it in my database manually.







2 Answers, 1 is accepted

Sort by
0
Vasil
Telerik team
answered on 15 Jan 2015, 11:35 AM
Hello Simon,

You need to get the data from the AsyncUpload, and use it in your hash when you add new record.

For example in the FileUploaded handler you can make the image global variable in your Page.

Then ItemInserting hadnler to use such approach:
newValues.Add ("ExampleFieldName" , image );

Additionally you can find another example with RadGrid and AsyncUpload with manual operations here:
http://demos.telerik.com/aspnet-ajax/controls/examples/integration/gridandradasyncupload/defaultcs.aspx?product=grid
Such approach will work for all data bound controls.

Regards,
Vasil
Telerik
0
Riad
Top achievements
Rank 1
answered on 16 Jan 2015, 06:41 PM
Hi Vasil,
    thank you. I dind't tough about storing my image in a global variable until I need it. 

Thanks
Tags
DataForm
Asked by
Riad
Top achievements
Rank 1
Answers by
Vasil
Telerik team
Riad
Top achievements
Rank 1
Share this question
or