Kevin Price
Top achievements
Rank 1
Kevin Price
asked on 20 Apr 2010, 09:03 PM
Been searching around a bit for the Grid samples with upload and haven't found one that has a way of using an edit from with RadUpload. All seem to rely on using the Image or Attachment column which is great, but I have a couple of columns showing in the grid that are not editable and am using the edit form. Any pointers would be greatly appreciated.
Thanks,
Kevin
Thanks,
Kevin
4 Answers, 1 is accepted
0
Kevin Price
Top achievements
Rank 1
answered on 21 Apr 2010, 02:57 PM
Maybe it doesn't exist? :)
0
Hi Kevin Price,
All the best,
Maria Ilieva
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.
Please review the following online example which provides approach for similar scenario.
I hope it helps.
All the best,
Maria Ilieva
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
Kevin Price
Top achievements
Rank 1
answered on 22 Apr 2010, 02:31 PM
Thanks Maria, but that sample doesn't really show how to use it within a form template. I hammered this out with a little bouncing back and forth with support and wrote the following code which seems to handle this quite well. Assuming the javascript from the sample you mentioned is already on the page....
Added the column:
In my EditFormSettings - EditFormType="Template", nice boring HTML and then added the RadUpload control:
In the code behind:
Now that sample will work in an edit form template :).
Thanks,
Kevin
Added the column:
<telerik:GridAttachmentColumn MaxFileSize="5000000" DataSourceID="ResResDS" EditFormHeaderTextFormat="Upload File:" |
HeaderText="Download" AttachmentDataField="uploadfile" AttachmentKeyFields="id" |
FileNameTextField="FileName" DataTextField="filename" UniqueName="AttachmentColumn"> |
</telerik:GridAttachmentColumn> |
</Columns> |
In my EditFormSettings - EditFormType="Template", nice boring HTML and then added the RadUpload control:
<tr> |
<td> |
File Attachment: |
</td> |
<td> |
<telerik:RadUpload MaxFileSize="5000000" runat="server" ID="FileUpload1" MaxFileInputsCount="1" |
AllowedFileExtensions=".zip,.jpg,.pptx,.docx,.doc,.xls,.pdf,.gif,.ppt,.txt,.csv" |
ControlObjectsVisibility="None"> |
</telerik:RadUpload> |
</td> |
</tr> |
In the code behind:
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) |
{ |
if (e.CommandName == RadGrid.UpdateCommandName || e.CommandName == RadGrid.PerformInsertCommandName) |
{ |
GridEditFormItem gridEditFormItem = (GridEditFormItem)e.Item; |
if (!(gridEditFormItem is GridEditFormInsertItem)) |
{ |
recid = (int)gridEditFormItem.GetDataKeyValue("id"); |
} //If more than one file is allowed, change to foreach |
RadUpload radUpload1 = (RadUpload)gridEditFormItem.FindControl("FileUpload1"); |
if (radUpload1.UploadedFiles.Count > 0) |
{ |
UploadedFile uf = radUpload1.UploadedFiles[0]; |
|
filedata = new byte[uf.ContentLength]; |
uf.InputStream.Read(filedata, 0, filedata.Length); |
filename = System.IO.Path.GetFileName(uf.FileName); |
} |
} |
} |
Now that sample will work in an edit form template :).
Thanks,
Kevin
0
Hello Kevin,
Best wishes,
Maria Ilieva
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.
Thank you for getting back to us.
I am glad that you have mentioned to find appropriate solution for your scenario.
Do not hesitate to contact Telerik Support if further assistance is needed.
Best wishes,
Maria Ilieva
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.