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

GridBinaryImageColumnEditor cannot get files

3 Answers 63 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alberto
Top achievements
Rank 1
Alberto asked on 29 Sep 2014, 09:23 AM
Hello,
I'm trying to implement the use of a GridBinaryImageColumn + GridBinaryImageColumnEditor to automatically manage the upload of an image into a RadGrid-
Data comes from custom classes, images come from a blob field in db and are rendered properly in grid; however, when I edit the record and try to upload a new image, my  GridBinaryImageColumnEditor always tells it cannot find any uploaded file.

My grid:

<telerik:RadGrid ID="grdLinee" runat="server" AutoGenerateColumns="false" AllowAutomaticUpdates="false" AllowSorting="true" AllowPaging="true" PageSize="10"
                OnNeedDataSource="grdLinee_NeedDataSource" AllowAutomaticInserts="true" AllowAutomaticDeletes="false" OnItemCommand="grdLinee_ItemCommand" OnSelectedIndexChanged="grdLinee_SelectedIndexChanged"
                AllowFilteringByColumn="false" MasterTableView-EditMode="InPlace" ShowHeader="true" ShowFooter="true" ShowStatusBar="true" Skin="Office2007">
                 <PagerStyle Mode="NextPrevAndNumeric" />
                <ClientSettings AllowKeyboardNavigation="true" EnablePostBackOnRowClick="true">
                    <Selecting AllowRowSelect="true" />
                </ClientSettings>
                <MasterTableView DataKeyNames="idCatalogoLinee" CommandItemDisplay="Top">
                    <Columns>
                        <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn"></telerik:GridEditCommandColumn>
                        <telerik:GridButtonColumn Text="Delete" CommandName="Delete" ButtonType="ImageButton" ConfirmText="Sei sicuro?" />
                        <telerik:GridBinaryImageColumn DataField="immagine" UniqueName="immagine" ResizeMode="Fit" DataType="System.Byte"></telerik:GridBinaryImageColumn>
//...

Code:

protected void grdLinee_ItemCommand(object sender, GridCommandEventArgs e)
        {
 switch(e.CommandName)
{
   case "Update":
 GridBinaryImageColumnEditor editor = (GridBinaryImageColumnEditor)item.EditManager.GetColumnEditor("immagine");
//editor.RadUploadControl.UploadedFiles.Count here is always 0
//...
}
}


I don't get any error in itemcommand, but always get 0 files   (and editor.UploadedFileContent.Length=0). The same update command is working properly with other database fields, which I can update: what am I missing to properly handle file upload?
Thanks for any hint,
al.

3 Answers, 1 is accepted

Sort by
0
Alberto
Top achievements
Rank 1
answered on 29 Sep 2014, 11:06 AM
Update: I could solve this problem by implementing a "RequestStart" function as per the sample at http://demos.telerik.com/aspnet-ajax/listview/examples/overview/defaultcs.aspx: I now can process uploaded files.
However, I now have another problem: I'm not able to process an update when I want both to update the image and other row values.
When I upload an image I get an error when extracting other row values:

try
                        {
                            GridEditableItem eItem = (GridEditableItem)item;
                            eItem.ExtractValues(values);
                            values.TryGetValue("nome", out nome);
//...

The call to ExtractValues causes an exception:

The value "System.Byte[]" is not of type "System.String" and cannot be used in this generic collection.

This is because my data class has a public property for images of type byte 
Public Property immagine As Byte()

However images are correctly and automatically loaded and displayed in grid when I bind my data, and also if I catch the error I'm able to update the image (when user makes an upload) OR the other data, when the user does not provide an image.

How can I process all of my data fields?


0
Alberto
Top achievements
Rank 1
answered on 29 Sep 2014, 12:42 PM
Maybe this can help anybody else: I solved this, I just had to parse values (with ExtractValues()) passing an HashTable instead of a Dictionary<string,string>!

0
Maria Ilieva
Telerik team
answered on 02 Oct 2014, 09:01 AM
Hi Alberto,

Thank you for sharing your solution for the presented issue.

I'm sure it will be of a big help for other users which face similar problems.

Regards,
Maria Ilieva
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Alberto
Top achievements
Rank 1
Answers by
Alberto
Top achievements
Rank 1
Maria Ilieva
Telerik team
Share this question
or