Quantcast
Channel: DevExpress Support Center (Examples)
Viewing all articles
Browse latest Browse all 7205

GridView - Batch Edit - How to use the upload control in Batch Edit mode

$
0
0
This example illustrates how to use the upload control in Batch edit mode. Note that all files are stored in memory until you call the update method.

1) Place UploadControl into the column's EditItem template:
[C#]
c.SetEditItemTemplateContent(container=>{Html.DevExpress().UploadControl(ucSettings=>{ucSettings.Name="uc";ucSettings.CallbackRouteValues=new{Controller="Home",Action="UploadControlUploadFile"};ucSettings.UploadMode=UploadControlUploadMode.Advanced;ucSettings.Width=Unit.Percentage(100);ucSettings.ClientSideEvents.TextChanged="OnTextChanged";ucSettings.ClientSideEvents.FileUploadComplete="OnFileUploadComplete";}).Render();});


2) Handle the grid's client-side BatchEditStartEditing event to set the grid's cell values to the upload control. It is possible to get the focused cell value using the e.rowValues property:
[JScript]
function OnBatchStartEditing(s, e){ browseClicked = false; $("#hf").val(e.visibleIndex);var fileNameColumn = s.GetColumnByField("FileName");if(!e.rowValues.hasOwnProperty(fileNameColumn.index))return;var cellInfo = e.rowValues[fileNameColumn.index]; setTimeout(function(){ SetUCText(cellInfo.value);}, 0);}

3) Handle the grid's client-side BatchEditConfirmShowing event to prevent data loss on the upload control's callbacks:
[JScript]
function OnBatchConfirm(s, e){ e.cancel = browseClicked;}
This "browseClicked" flag is set to true when the upload control starts uploading a file and to false when the file has been uploaded or the user starts editing another cell.

4) Handle the upload control's client-side TextChanged and FileUploadComplete events to automatically upload the selected file and update the cell value after:
[JScript]
function OnFileUploadComplete(s, e){ gridView.batchEditApi.SetCellValue($("#hf").val(), "FileName", e.callbackData); gridView.batchEditApi.EndEdit();}function OnTextChanged(s, e){if(s.GetText()){ browseClicked = true; s.Upload();}}

5) Handle the upload control's FileUploadComplete event to store the uploaded file in the session:
[C#]
publicActionResultUploadControlUploadFile(){varvisibleIndex=Convert.ToInt32(Request.Params["hf"]);UploadControlExtension.GetUploadedFiles("uc",null,(s,e)=>{varname=e.UploadedFile.FileName;e.CallbackData=name;if(Helper.Files.ContainsKey(visibleIndex))Helper.Files[visibleIndex]=e.UploadedFile.FileBytes;elseHelper.Files.Add(visibleIndex,e.UploadedFile.FileBytes);});returnnull;}

Now you can access all the uploaded files in the Batch action method. Clear the session storage after you have updated the files.

See also:
T191652: ASPxGridView - Batch Edit - How to use the upload control in Batch Edit mode
Question Comments

Added By: Hrushikesh Phapale at: 7/27/2015 8:59:39 AM    

hi,

I have tried the same bu getting error "DevExpress.Web.ASPxUploadControl is a type not a namespace" in home controller.
I have update the project to 15.1.3 version and I am using Visual studio 2013.
I also tried to find the reference of DevExpress.Web.ASPxUploadControl in my local machine but could not found any related assembly to it.

Really wondering what to do.

Please suggest any solution to it.


Viewing all articles
Browse latest Browse all 7205

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>