I noticed in the Grid / Attachment Column demo from here - http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/gridattachmentcolumn/defaultcs.aspx - that if I select the 'Edit' link, it requires me to attach the original file again. But what if I only needed to update the other columns and not the actual file? Is there a way to do this?
11 Answers, 1 is accepted
The field for the upload is empty because the path to the previously uploaded file from the client machine is not known during edit and cannot be automatically set in the field. However you can modify the example to avoid update of the download field if a new file is not entered. This way you can modify and update the other fields without necessarily specifying a file path and another file will be uploaded only when a new file is specified. Here is a code snippet on the needed modifications:
the Telerik team
But my problem is when I update a field without uploading a new file, I get the message that the file can not be read when I click on the link to open it after the update.
Create new record works, but not to update without having to upload a new file.
You should also make sure you have modified the Update command as shown in the SqlDataSource1_Updated event, this way after update the SqlDataSource will not modify the data in the column that holds the file, and it will still be available after you click the link.
To resolve the issue you simple need to ensure that the update command of the SqlDatasource does not modify the contents of the field holding the file:
problem with fileData......
fileData is the third argument of the UpdateInsertFileData function and second parameter in the SQL query that will actually perform the update of the database. Depending on the custom logic in the procedure you may wish to use this argument or not if the user has not uploaded a new file and you do not wish to update the corresponding BinaryData field with new values.
Still a small problem remains. When I save the edited form not collapse, its open. But the update was performed.
But I have to click cancel to collapse
This my code:
You can try disabling the automatic operations for the grid to see if this helps:
But the database is not update with insert or update.....
When using automatic operations in the grid (AllowAutomaticUpdates="true"), the grid automatically calls the update query / method of the relevant datasource control and closes the edit form.
The other option is manually handling the update / insert operations of the control (in this case AllowAutomaticUpdates / Inserts = "false") then in the grid's Update / Insert command event you perform the operation to the database and rebind the control (RadGrid1.Rebind()) - this will also close the edit form.
The above are the two recommended ways to save grid's data to the database and have the edit form properly closed.