Hi All,
I am trying to use the GridAttachmentColumn in the Grid, but don't want to have to use an SQLDataSource control.
I have objects and data-layers for the retrieving and control of my file objects, so I was wondering how I fill out this column with the bound information from my datalayer (it is a DataSet)?
At this point, it seems I need to abandon this new column type and use ItemTemplates instead with a nested RadUpload control.
Anyone had any experience with binding this column programmatically?
Thanks,
Steele.
I am trying to use the GridAttachmentColumn in the Grid, but don't want to have to use an SQLDataSource control.
I have objects and data-layers for the retrieving and control of my file objects, so I was wondering how I fill out this column with the bound information from my datalayer (it is a DataSet)?
At this point, it seems I need to abandon this new column type and use ItemTemplates instead with a nested RadUpload control.
Anyone had any experience with binding this column programmatically?
Thanks,
Steele.
7 Answers, 1 is accepted
0
Hello Steele,
You can bind the column to an ObjectDataSource control through the DataSourceID. Thus, you can interface your business data layer with the column.
I am not sure I understand what do you mean by that your data layer is a DataSet? Do you mean that all your attachments that you can download through the GridAttachmentColumn are loaded in a DataSet and reside in server memory? Isn't that a huge overhead if this is the case? The idea behind the GridAttachmentColumn is to bind to a data source control that will fetch a single item from your data source containing your binary attachment data and send it over through the response. Thus, large attachment files are not stored in server memory. If this is not the case, can you, please, clarify?
Regards,
Veli
the Telerik team
You can bind the column to an ObjectDataSource control through the DataSourceID. Thus, you can interface your business data layer with the column.
I am not sure I understand what do you mean by that your data layer is a DataSet? Do you mean that all your attachments that you can download through the GridAttachmentColumn are loaded in a DataSet and reside in server memory? Isn't that a huge overhead if this is the case? The idea behind the GridAttachmentColumn is to bind to a data source control that will fetch a single item from your data source containing your binary attachment data and send it over through the response. Thus, large attachment files are not stored in server memory. If this is not the case, can you, please, clarify?
Regards,
Veli
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Steele
Top achievements
Rank 1
answered on 09 Dec 2010, 11:42 PM
It seems that my description of my requirements were lacking.
I am trying to avoid using SQLDataSource controls or the like as the inclusion of them within the interface level goes against the design principles laid down in our framework.
My data layer is not a DataSet but rather the information drawn from it is. The methodology in fact causes no file data to be stored in memory, as I am replicating (or rather, trying to replicate) the DataSource control that is provided in the examples. But I need some way of assigning the file data from my DataSet column to the GridAttachmentColumn.
So my object enables me to get the file details (name, date uploaded, etc) and also has fetch/save routines for the file data itself. I can bind the details just fine (straight out binding to a grid) but cannot find a way to hook up a binding to my fetch/save routines for the file data.
Does that explain better where I am coming from?
Steele.
I am trying to avoid using SQLDataSource controls or the like as the inclusion of them within the interface level goes against the design principles laid down in our framework.
My data layer is not a DataSet but rather the information drawn from it is. The methodology in fact causes no file data to be stored in memory, as I am replicating (or rather, trying to replicate) the DataSource control that is provided in the examples. But I need some way of assigning the file data from my DataSet column to the GridAttachmentColumn.
So my object enables me to get the file details (name, date uploaded, etc) and also has fetch/save routines for the file data itself. I can bind the details just fine (straight out binding to a grid) but cannot find a way to hook up a binding to my fetch/save routines for the file data.
Does that explain better where I am coming from?
Steele.
0
Yes, better understood. I believe the GridAttachmentColumn would not come in very handy in your scenario, then. Not that it cannot be configured to work in this case, but would not be less of hassle than using a GridTemplateColumn. With the latter you can have a button in the ItemTemplate to download attachments and a RadUpload in the EditItemTemplate to upload them to your database:
<telerik:RadGridID="RadGrid1"runat="server"><MasterTableView><Columns><telerik:GridTemplateColumn><ItemTemplate><asp:LinkButtonID="DownloadButton"runat="server"CommandName="DownloadAttachment"Text="Download"></asp:LinkButton></ItemTemplate><EditItemTemplate><telerik:RadUploadID="AttachmentUpload"runat="server"></telerik:RadUpload></EditItemTemplate></telerik:GridTemplateColumn></Columns></MasterTableView></telerik:RadGrid>
Using RadGrid's ItemCommand event you can both stream download the attachment, as well as upload one on update:
protectedvoidRadGrid1_ItemCommand(objectsource, GridCommandEventArgs e){if(e.CommandName == RadGrid.DownloadAttachmentCommandName){GridDataItem dataItem = (GridDataItem)e.Item;stringfileName;//use dataItem.GetDataKeyValue() to get data keys incl. filenamebyte[] binaryData;//populate binaryData with attachment dataResponse.Clear();Response.ContentType ="application/octet-stream";Response.AddHeader("content-disposition","attachment; filename="+ fileName);Response.BinaryWrite(binaryData);Response.End();}if(e.CommandName == RadGrid.UpdateCommandName ||e.CommandName == RadGrid.PerformInsertCommandName){RadUpload attachmentUpload = (RadUpload)e.Item.FindControl("AttachmentUpload");if(attachmentUpload.UploadedFiles.Count > 0){UploadedFile file = attachmentUpload.UploadedFiles[0];System.IO.Stream stream = file.InputStream;byte[] binaryData =newbyte[stream.Length];stream.Read(binaryData, 0, (int)stream.Length);stream.Seek(0, System.IO.SeekOrigin.Begin);//binaryData contains your uploaded content//you can save to your database}}}
Veli
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Jonathan
Top achievements
Rank 1
answered on 18 Feb 2011, 09:07 PM
How exactly do you place that Binary data into the InsertParameter?
I'm using an ObjectDataSource control to do this and I want to place that binary data into the InsertParameter of the ObjectDataSource control. However, the only available property to which a value can be assigned is DefaultValue, which is a string. The BinaryData is a 1-dimensional byte array. How do you get that to work?
I'm using an ObjectDataSource control to do this and I want to place that binary data into the InsertParameter of the ObjectDataSource control. However, the only available property to which a value can be assigned is DefaultValue, which is a string. The BinaryData is a 1-dimensional byte array. How do you get that to work?
0
Hi Jonathan,
You can use an event handler for the Inserting event of the ObjectDataSource control. The insert operation is performed by calling the Insert method of the data source control inside RadGrid's PerformInsert command:
Veli
the Telerik team
You can use an event handler for the Inserting event of the ObjectDataSource control. The insert operation is performed by calling the Insert method of the data source control inside RadGrid's PerformInsert command:
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e){ if (e.CommandName == RadGrid.PerformInsertCommandName) { AttachmentDataSource.Insert(); //the data source control }}Veli
the Telerik team
0
Jonathan
Top achievements
Rank 1
answered on 21 Feb 2011, 03:47 PM
Hey Veli,
You gave me a brilliant idea that worked.
Here's my implementation for reference of anyone else who may have the same problem:
Because the ObjectDataSource.InserParameters.Value uses a String, I can't pass a 1-Dimensional array to it directly. So in the RadGrid.InsertCommand, I grab the file stream and store it into a Session variable which automatically assumes the DataType of whatever is being assigned to it:
Then in the ObjectDataSource.Inserting event, I pass the contents of the session variable (which now assumes the datatype of a 1-dimensional array of Bytes) directly to the insert parameter which would already be of the correct data type:
This way, I don't have to call the Insert command of the ObjectDataSource directly. I simply ride the sequence of events as they bubble up through the object hierarchy from the instant the InsertCommand is triggered from the RadGrid by the user.
This method seems more elegant to me.
Thanks for your suggestions, Veli.
Regards,
John
You gave me a brilliant idea that worked.
Here's my implementation for reference of anyone else who may have the same problem:
Because the ObjectDataSource.InserParameters.Value uses a String, I can't pass a 1-Dimensional array to it directly. So in the RadGrid.InsertCommand, I grab the file stream and store it into a Session variable which automatically assumes the DataType of whatever is being assigned to it:
If e.Item.OwnerTableView.DataSourceID = "ObjectDataSource4" Then 'Stream the file data into the object. Dim ru As RadUpload = DirectCast(item("Document_Store").Controls(0), RadUpload) If ru.UploadedFiles.Count > 0 Then Dim file As UploadedFile = ru.UploadedFiles(0) Dim stream As System.IO.Stream = file.InputStream Dim BinaryData(stream.Length - 1) As Byte stream.Read(BinaryData, 0, CInt(stream.Length)) Session("File") = BinaryData End IfEnd IfThen in the ObjectDataSource.Inserting event, I pass the contents of the session variable (which now assumes the datatype of a 1-dimensional array of Bytes) directly to the insert parameter which would already be of the correct data type:
Dim pars As IDictionary = e.InputParameters pars("Document_Store") = Session("File")This way, I don't have to call the Insert command of the ObjectDataSource directly. I simply ride the sequence of events as they bubble up through the object hierarchy from the instant the InsertCommand is triggered from the RadGrid by the user.
This method seems more elegant to me.
Thanks for your suggestions, Veli.
Regards,
John
0
SKande
Top achievements
Rank 2
answered on 16 May 2013, 10:42 PM
How do we delete the file attachment using the Link button template because it does not have a unique name to get the file name