RadBinaryImage DataValue null inside Dataform

3 posts, 0 answers
  1. Riad
    Riad avatar
    12 posts
    Member since:
    Nov 2014

    Posted 12 Jan 2015 Link to this post

    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();
            RPKNewsData test = new RPKNewsData(newValues);

    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. Vasil
    Vasil avatar
    1604 posts

    Posted 15 Jan 2015 Link to this post

    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:
    Such approach will work for all data bound controls.

  3. Riad
    Riad avatar
    12 posts
    Member since:
    Nov 2014

    Posted 16 Jan 2015 Link to this post

    Hi Vasil,
        thank you. I dind't tough about storing my image in a global variable until I need it. 

Back to Top