select

Grid / Attachment column

Rate this demo: Feedback
Run example in: C# VB.NET Change Skin:
Vista
  • BlackBlack
  • DefaultDefault
  • ForestForest
  • HayHay
  • Office2007Office2007
  • OutlookOutlook
  • SimpleSimple
  • SitefinitySitefinity
  • SunsetSunset
  • TelerikTelerik
  • VistaVista
  • Web20Web20
  • WebBlueWebBlue
  • Windows7Windows7
Next database reset in 1 hours, 39 minutes, 40 seconds
Choose an option and download attachment from a RadGrid data item:

Alternatively, choose a file and press "Download" to fire the event from code:
select
Add new recordRefresh
 IDFileNameUploadDateUploadedByDownload
Edit1ViewState.gif9/16/2009 2:00:00 PMJohn SmithViewState.gif
Edit2Appointments.xml9/16/2009 7:00:00 PMMaria TrujilloAppointments.xml
Edit3Sushi.pdf9/17/2009 5:00:00 PMYamada TaroSushi.pdf
Edit4Demo.png9/19/2009 9:00:00 AMRobert De BoronDemo.png
Edit5Customers.doc9/21/2009 6:00:00 PMSergio BatistaCustomers.doc
Edit6Customers.xls9/21/2009 7:00:00 PMSergio BatistaCustomers.xls
Edit7Description.htm9/22/2009 10:00:00 AMJean FrancoisDescription.htm
Note: Maximum file size allowed: 1MB

Example Source Code & Description

Instructions
Open in new window
  • GridAttachmentColumn provides an easy way to quickly setup download/upload functionality for files stored in binary form in your database. The column binds to a separate data source control that retrieves the actual binary data from your database, providing data key values from the main RadGrid data source to the SQL SELECT query returning the binary data.

    To set up GridAttachmentColumn, a minimum collection of properties need to be set:

    • DataSourceID - specifies the ID of the data source control that retrieves the binary attachment data
    • AttachmentKeyFields - specifies the field names from RadGrid's data source that are used to populate the attachment data source select parameters
    • AttachmentDataField - specifies the field from GridAttachmentColumn's data source where the attachment is stored as binary data

    Additionally, GridAttachmentColumn provides the following properties for extented customization:

    • FileName - specifies the file name of the downloaded attachment (default value: attachment)
    • FileNameTextField - specifies the name of the field from RadGrid's data source, the values of which will be used as file names of the downloaded attachments
    • FileNameTextFormatString - specifies the format string used to format the value of the field specifies by the FileNameTextField property
    • Text - specifies the text of the download button
    • DataTextField - specifies the data field from parent GridTableView's data source, the values of which will be used for the download button text
    • DataTextFormatString- specifes the format string used to format the value of the field specified by DataTextField
    • AllowedFileExtensions - specifies the allowed file extensions
    • MaxFileSize - specifies the maximum allowed file size in bytes

    The download button fires RadGrid's ItemCommand event with command name DownloadAttachment that can be intercepted to modify the download properties, or manually download the attachment. The event can also be fired from code either on the server, or on the client using GridDataItem.FireCommandEvent() or GridTableView.fireCommand() methods, respectively.

    In edit mode, GridAttachmentColumn provides a RadUpload control that can be used to upload and save files in the database. A grid column editor of type GridAttachmentColumnEditor gives you access to the RadUpload control back on the server. A note here is that the uploaded binary data is not automatically extracted using GridTableView.ExtractValuesFromItem(). This also means that no file data will be automatically saved to the column's data source even when automatic data source operations are set up for RadGrid.

    Finally, due to the limitations of the javascript XmlHttpRequest object used for AJAX, to download or upload attachments, AJAX needs to be temporarily disabled, so that the page performs a full postback. When downloading, RadGrid's client-side OnCommand event can be used to intercept a download action and disable AJAX, while for uploads, we use the approach demonstrated in the RadGrid and RadUpload integration demo.

    For additional information on GridAttachmentColumn, please refer to the respective section in the RadGrid column types topic from the online documentation.

Compatible with ASP.NET 2.0, 3.5 AJAX enabled Accessibility Verified!Valid XHTML 1.1! Optimized for Visual Studio 2005, 2008
Copyright 2002-2010 © Telerik. All right reserved  | 
Telerik Inc., 460 Totten Pond Rd, Suite 640, Waltham, MA 02451

www.telerik.com  |  Terms of Use  |  Contact Us