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

GridAttachmentColumn - ItemDataBound object source

4 Answers 158 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Siddhartha Savant
Top achievements
Rank 1
Siddhartha Savant asked on 12 Mar 2010, 10:59 PM
Hi,

I have a GridAttachmentColumn on a RadGrid. How can I bind a source to the Attachement column from the codebehind and not using DataSourceID. I tried gettng the control by handling Item Data bound even but was not able to get it.

Thanks,
Sid

4 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 17 Mar 2010, 02:53 PM
Hi Siddhartha,

The GridAttachmentColumn does not support non-declarative data-binding. It requires that a DataSourceID is specified, so that the column fetches the attachment data from the data source control when a download command is initiated. The whole idea behind having a separate data source control is to fetch presumably large data blocks (the attachment) from the underlying data store only when required. This is when a user wants to download a specific attachment. If you have already pre-fetched all attachments before they are needed, this, essentially, defeats the purpose of having a separately databound column. In this case,  you can use a GridTemplateColumn with a button in the ItemTeamplate and a RadUpload in the EditItemTemplate.

Kind regards,
Veli
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Siddhartha Savant
Top achievements
Rank 1
answered on 17 Mar 2010, 04:10 PM
Hi Veli,

Thank you for your response. We may take the Item Template option, but wanted to check if that is the cleanest solution. What we needed is a Grid which has a inline Attachment edit option and we are able to get the view uploaded document (which should open excel/acrobat app or whatever is associated to the extension) in the non-edit mode. Exactly the way GridAttachmentColumn example is. We do have two objects one which has the product information and a separate object for storing binary data as shown in the example but we have 3-tiers so cannot access the data directly using SQLDataSource. I have have handled grids NeedDataSource even to bind the product object to the grid, what I want to do is bind binary object conatining attachment details for the product to the GridAttachmentColumn. I tried overriding ItemDatabind event but I am unable to get the GridAttachmentColumn handle. please advice..

Object Model -

Product
Id
Name
Price
Qty

ProductAttachment
Id
ProductId
Attachment (binary)

Thanks,
Sid 
0
Veli
Telerik team
answered on 18 Mar 2010, 11:21 AM
Hello Siddhartha,

In this case the most straightforward approach you can take is not bind your attachment data source to any column at all. Instead, use a GridTemplateColumn to define a custom button in the ItemTemplate. The button would fire a custom command, let's call it ViewAttachment. Using RadGrid's ItemCommand event, you can handle your custom command. Inside, get the product ID and find the related record in the attachment data source. Then you can stream the binary content through the response.

For  the insert/update part, put a RadUpload in the EditItemTemplate of the GridTemplateColumn. Configure it to accept a single uploaded file and specify the allowed file extensions and mime types. Thus, your users can use the upload to attach files to the grid record.

Finally, to save the updated or inserted record, use RadGrid's ItemCommand event, again, to handle the Update and Insert commands. Inside, get the updated values and save them to the data layer.

All this is demonstrated in a sample page I have attached. Check it out. Note that I bind the RadGrid to the main record set, but do not have a separate databinding process for the attachments. I simply use a custom grid command to find the related attachment and stream it.

All the best,
Veli
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Siddhartha Savant
Top achievements
Rank 1
answered on 18 Mar 2010, 04:03 PM
Thanks veli, this would work. I had something similar but had used HTML file control instead of RadUpload which looks better. I do have an Ajax issue, would send the code if I am not able to solve it.

Thanks,
Sid
Tags
Grid
Asked by
Siddhartha Savant
Top achievements
Rank 1
Answers by
Veli
Telerik team
Siddhartha Savant
Top achievements
Rank 1
Share this question
or