BinaryImage Insert/Updates w/ sqldatasource

2 posts, 0 answers
  1. ToltingColtAcres
    ToltingColtAcres avatar
    92 posts
    Member since:
    Nov 2010

    Posted 27 Sep 2018 Link to this post

    Using the following code I found in one of the demos. The radgrid is bound to a sqldatasource.

    When I update or insert, there is no parameter created for the binary image to send data to the database ( I have added onUpdating and onInserting events to the sql data source, and have inspected the DBParameters collection, and there is no parameter passed containing the binary data of the image.) other columns from the grid are passed as parameters correctly, there is simply no sqlparameter for the image data.

    How can I rectify this?

    Also, the radupload dialog to select a image does not seem to work with the allowedfileextensions option. Also I specify jpg only, I see all file types in the selection dialog. Is there a way to only show those files w/ the allowed extensions?

     

    <telerik:GridTemplateColumn DataField="Data" HeaderText="Image" UniqueName="Upload">
     <ItemTemplate>
      <telerik:RadBinaryImage runat="server" ID="RadBinaryImage1" DataValue='<%#Eval("Data") %> AutoAdjustImageControlSize="false" Height="80px" Width="80px" ToolTip='<%#Eval("Name", "Photo of {0}") %>' AlternateText='<%#Eval("Name", "Photo of {0}") %>'> 
      </telerik:RadBinaryImage>
     
    </ItemTemplate>
     <EditItemTemplate>
      <telerik:RadAsyncUpload RenderMode="Lightweight" runat="server" ID="AsyncUpload1" AllowedFileExtensions="jpg" >
      
    </telerik:RadAsyncUpload>
     </EditItemTemplate>
     </telerik:GridTemplateColumn>

     

  2. Marin Bratanov
    Admin
    Marin Bratanov avatar
    4713 posts

    Posted 01 Oct 2018 Link to this post

    Hi,

    I'm assuming you are referring to the "Display and edit images in RadGrid" demo. If not, I advise that you review it. Here are the key points:

    • the InsertCommand and UpdateCommand events of the grid is used to fetch the files uploaded through a RadAsyncUpload instance, and this is where they are stored in the database.
    • the FileUploaded event of the async upload is used to raise flags that are used for validation on those events

    If you are looking at the Column Types demo, you will see a similar approach used to put the uploaded files in the database:

    • the ItemCommand event of the grid is used to fetch the file file data into fields global for the page class, so they can later be used
    • the Updated and Inserted events of the SqlDataSource are used to fire another command that will use the file data and store it in the database

    On showing only certain file types to the user, the following article explains how you can achieve that: https://www.telerik.com/support/kb/aspnet-ajax/upload-(async)/details/how-to-filter-file-selection-in-the-upload-dialog.


    Regards,
    Marin Bratanov
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top