- Home
- Forum
- ASP.NET Web Forms
- Grid - inlineformtemplate - Upload -image
Grid - inlineformtemplate - Upload -image
Thanks for contacting Syncfusion support.
Query: Its's possible Grid Upload picture in inlineformtemplate?
Yes, it’s possible to upload picture in Grid inlineformtemlate. We have created a sample based on your requirement and refer to the sample & code example as below.
Sample: Sample-uploadbox
|
<script type="text/template" id="CustomerForm"> <b>Order Details</b> <table cellspacing="10"> . . .
<tr> <td style="text-align: right;" valign="top">Picture </td> <td style="text-align: left" valign="top"> <div id="UploadInput"></div> </td>
</tr> </table> |
In Grid ActionComplete event, we have rendered the uploadbox control and bind the corresponding action. Refer to the code example as below.
|
<div> <ej:Grid ID="OrdersGrid" runat="server" AllowPaging="True" > <ClientSideEvents ActionComplete="complete" /> <FilterSettings FilterType="Menu" /> <Columns> <ej:Column Field="OrderID" IsPrimaryKey="True" TextAlign="Right" Width="90" /> <ej:Column Field="CustomerID" Width="100" /> <ej:Column Field="EmployeeID" TextAlign="Right" Width="100" /> </Columns> <EditSettings AllowEditing="True" AllowAdding="True" AllowDeleting="True" EditMode="InlineFormTemplate" InlineFormTemplateID="#CustomerForm"></EditSettings> </ej:Grid> function complete(args) { //render uploadbox control if ((args.requestType == "beginedit" || args.requestType == "add")) { $('#UploadInput').ejUploadbox({ saveUrl: "saveFiles.ashx", }); } |
We have uploaded the image file in uploadbox and saved the image in required file path.
|
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; context.Response.Write("Hello World"); string targetFolder = HttpContext.Current.Server.MapPath("") + "\\New folder\\"; if (!Directory.Exists(targetFolder)) { Directory.CreateDirectory(targetFolder); } HttpRequest request = context.Request; HttpFileCollection uploadedFiles = context.Request.Files; if (uploadedFiles != null && uploadedFiles.Count > 0) { for (int i = 0; i < uploadedFiles.Count; i++) { string fileName = uploadedFiles[i].FileName; int indx = fileName.LastIndexOf("\\"); if (indx > -1) { fileName = fileName.Substring(indx + 1); } uploadedFiles[i].SaveAs(targetFolder + "\\" + fileName); } }
|
Refer to the Demo in following link.
UploadBox: http://asp.syncfusion.com/demos/web/uploadbox/events.aspx
InlineFormTemplate: http://asp.syncfusion.com/demos/web/grid/inlineformonlocaldata.aspx
If we misunderstood your requirement please share us more information which will be helpful to provide better solution at the earliest.
Regards,
Balaji Marimuthu
Attachment: Inline_Editing_e3ed6dcc.rar
Please confirm the following details. It will help us to provide the prompt solution
If this is not meet your requirement so please elaborate the requirement, it will be helpful to provide the better solution.
Regards,
Prasanna Kumar N.S.V
Your requirement has been achieved by the actionBegin event of ejGrid. This event triggers for every grid action before its starts. In this event, we check the condition with the requestType and upload the image file using xhrPerformUpload function.
We hide the upload dialog box by disabling the showFileDetails API of ejUploadBox and display the image name using the fileselect event of ejUploadBox. This event fires when the Upload process ends in Error and we can able to get the filename in the arguments, and display the file name.
Please find the following code example, screenshot and sample:
|
<div> <ej:Grid ID="OrdersGrid" runat="server" AllowPaging="True" > <ClientSideEvents ActionComplete="complete" ActionBegin="begin" /> <FilterSettings FilterType="Menu" /> <Columns> <ej:Column Field="OrderID" IsPrimaryKey="True" TextAlign="Right" Width="90" /> <ej:Column Field="CustomerID" Width="100" /> <ej:Column Field="EmployeeID" TextAlign="Right" Width="100" /> </Columns> <EditSettings AllowEditing="True" AllowAdding="True" AllowDeleting="True" EditMode="InlineFormTemplate" InlineFormTemplateID="#CustomerForm"></EditSettings> </ej:Grid> <script> function complete(args) { //render uploadbox control if ((args.requestType == "beginedit" || args.requestType == "add")) { $('#UploadInput').ejUploadbox({ saveUrl: "saveFiles.ashx", showFileDetails: false, fileSelect : "select", }); } } function begin(args) { if (args.requestType == "save") { var upload = $('#UploadInput').ejUploadbox("instance"); var wrapper = upload.diaObj.wrapper; var fileItem = wrapper.find(".e-ul li.e-upload-file"); upload._xhrPerformUpload($(fileItem).data("file")); } }
function select(args) { var filename = args[0].name; $("#par").html(filename); }
|
Screenshot:
Sample: http://www.syncfusion.com/downloads/support/forum/120926/ze/Sample-uploadbox584136372_(2)-86569105
Refer to the Help documents for the actionBegin and fileSelect events,
actionBegin : http://help.syncfusion.com/js/api/ejgrid#events:actionbegin
fileSelect : http://help.syncfusion.com/js/api/ejuploadbox#events:fileselect
Regards,
Prasanna Kumar N.S.V
Attachment: uploadscreen_66988cb8.rar
Attachment: Inline_Editing_be0f305f.rar
On analyzing your sample, we found that an improper URL has been mentioned in the SaveFiles.ashx. So, please mention the proper URL in the SaveFiles.ashx file.
Please find the screenshot and modified sample:
Screenshot of an uploaded image :
Sample: http://www.syncfusion.com/downloads/support/forum/120926/ze/Inline_Editing-2107326925
Regards,
Prasanna Kumar N.S.V
- 8 Replies
- 3 Participants
-
PR Pratheep
- Oct 28, 2015 09:19 AM UTC
- Nov 3, 2015 07:23 AM UTC