- Home
- Forum
- ASP.NET Web Forms
- inlineformtemplate - grid - image upload
inlineformtemplate - grid - image upload
Attachment: Inline_Editing_e8b2d31f.rar
Before proceeding with your query, we request you to provide the following information which will be helpful to analyze the issue and provide you the solution as soon as possible.
Would you like to upload and send the file along with the Grid records while sending the post for saving the Grid content in the Server-side?
Regards,
Seeni Sakthi Kumar S.
Attachment: imageupload_8f86b6af.rar
We have used a form element to save the image/file along with the Grid records. ejDataMangers should works with the json objects and not with other type of objects. So we send a ajax post of a form element to achieve this requirement. Please refer to the below code example.
|
<ej:Grid ID="OrdersGrid" runat="server" AllowPaging="True"> <ClientSideEvents ActionComplete="complete" ActionBegin="begin" /> <Columns> <ej:Column Field="EmployeeID" TextAlign="Right" /> </Columns> <EditSettings AllowEditing="True" AllowAdding="True" AllowDeleting="True" EditMode="inlineformtemplate" InlineFormTemplateID="#CustomerForm"></EditSettings> <ToolbarSettings ShowToolbar="True" ToolbarItems="add,edit,delete,update,cancel"></ToolbarSettings> </ej:Grid> <script type="text/template" id="CustomerForm"> <b>Order Details</b> <table cellspacing="10"> <tr> <td style="text-align: right;">Employee ID </td> <td style="text-align: left"> <input id="EmployeeID" name="EmployeeID" value="{{:EmployeeID}}" class="e-field e-ejinputtext valid" /> </td> </tr> <tr> <td style="text-align: right">Picture </td> <td style="text-align: left"> <div id="UploadInput"></div> <p id="par"></p> </td> </tr> </table>
</script> <script> function begin(args) { if (args.requestType == "save") { args.cancel = true; //Updating the file as one of the column data args.data["Photo"] = window.uploadData.files; window.uploadData["editData"] = new FormData(); //Converting the grid data to form data to send files to controller for (var d in args.data) uploadData.editData.append(d, args.data[d]); //Updating the form before sending the ajax post. proxy = this; $.ajax({ url: window.uploadData.url, type: 'POST', data: window.uploadData.editData, success: function () { proxy.refreshContent(); } }); //Canceling the request args.cancel = true;
} } function complete(args) { if (args.requestType == "beginedit" || args.requestType == "add") {
window.uploadData = {};//A Global var to track and hold file uploading info window.uploadData.url = args.requestType == "add" ? "/Default.aspx/PerformInsert" : "/Default.aspx/PerformUpdate"; //Render upload control $("#UploadInput").ejUploadbox({ asyncUpload: false, multipleFilesSelection: false, buttonText: { browse: "Select Photo" }, fileSelect: function (args) { //Get the file from fileSelect event uploadData["files"] = args[0].rawFile; //inially copying the file to global variable and same can be retrieved in the save action. var filename = args[0].name; $("#par").html(filename); } }); } }
[WebMethod] public void PerformInsert(EmployeeInsertModel employee) {
NorthwindDataContext db = new NorthwindDataContext();
db.EmployeePhotos.InsertOnSubmit(new EmployeePhoto() { EmployeeID = employee.EmployeeID, Photo = employee.Photo != null ? GetByteStream(employee.Photo) : null }); db.SubmitChanges();
} //Convert the posted file to byte[] public byte[] GetByteStream(HttpPostedFileBase file) {
byte[] bt = new byte[file.InputStream.Length]; MemoryStream ms = new MemoryStream(); ms.Read(bt, 0, (int)file.InputStream.Length); return bt; } public class EmployeeInsertModel {
public int EmployeeID { get; set; } public HttpPostedFileBase Photo { get; set; } } [WebMethod] public void PerformUpdate(EmployeeInsertModel employee) {
NorthwindDataContext db = new NorthwindDataContext();
EmployeePhoto emp = (EmployeePhoto)db.EmployeePhotos.Single(s => s.EmployeeID == employee.EmployeeID);
emp.EmployeeID = employee.EmployeeID; emp.Photo = employee.Photo != null ? GetByteStream(employee.Photo) : null;
db.SubmitChanges();
|
Regards,
Seeni Sakthi Kumar S.
Attachment: upload_141d5937.rar
We have created a custom sample request for your requirement and created a new support incident under your account. Please log on to our support website to check for further updates.
https://www.syncfusion.com/account/login?ReturnUrl=/support/directtrac/incidents
Regards,
Seeni Sakthi Kumar S.
We will update you further updates of custom Sample in your new incident.
Regards,
Seeni Sakthi Kumar S.
- 7 Replies
- 2 Participants
-
PR Pratheep
- Nov 16, 2015 05:25 AM UTC
- Nov 20, 2015 04:02 AM UTC