Articles in this section
Category / Section

How to upload the image without the upload box?

1 min read

This knowledge base explains How to upload the image in Inline-form Template without using Upload button.

Solution:

In uploadBox when we upload the image the saveURL will be triggered once when we click the upload button in uploadBox.

If we need to trigger the saveURL when we click on save button in inline-form Template, we need to hide upload button by defining false for the showFileDetails API of ejUploadBox.

In actionBegin event we will triggered the saveURL of ejUploadBox using Upload method of ejUploadBox

 

1. Render the Grid as follows.

 

HTML

 

<div id="OrdersGrid"></div>

 

JS

<script type="text/javascript">
        $(function () {
            $("#OrdersGrid").ejGrid({
                // the datasource "window.gridData" is referred from jsondata.min.js
                dataSource: window.gridData,
                allowPaging: true,
                editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true, editMode: ej.Grid.EditMode.InlineTemplateForm, inlineFormTemplateID:"#CustomerForm" },
                toolbarSettings: { showToolbar: true, toolbarItems : ["add", "edit", "delete", "update", "cancel"] },
                actionComplete: "complete",
                actionBegin: "begin",
                columns: [
                        { field: "OrderID", headerText: "Order ID",isPrimaryKey:true, width: 100 },
                        { field: "CustomerID", headerText: "Customer ID", width: 100 },              
                        { field: "EmployeeID", headerText: "Employee ID", width: 100 },
                ]
            });
        });
    </script>

 

ASP

<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
    <div>
        <ej:Grid ID="OrdersGrid" runat="server"  AllowPaging="True" >
            <ClientSideEvents ActionComplete="complete" ActionBegin="begin" />
            <ToolbarSettings ShowToolbar="true" ToolbarItems="add,edit,delete,update,cancel"></ToolbarSettings>
             <Columns>
                <ej:Column Field="OrderID" IsPrimaryKey="True" Width="90" />
                <ej:Column Field="CustomerID"  Width="100" />
                <ej:Column Field="EmployeeID" Width="100" />
            </Columns>
           <EditSettings AllowEditing="True" AllowAdding="True" AllowDeleting="True" EditMode="InlineFormTemplate" InlineFormTemplateID="#CustomerForm"></EditSettings>
        </ej:Grid>
    </div>
</asp:Content>

 

[CS]
 
namespace SyncfusionASPNETApplication2
{
public partial class _Default : Page
    {      
     protected void Page_Load(object sender, EventArgs e)
        {
            this.OrdersGrid.DataSource = OrderRepository.GetAllRecords();
            this.OrdersGrid.DataBind();
        }
    }
}

 

MVC

@(Html.EJ().Grid<MvcApplication14.OrdersView>("OrdersGrid")
  .Datasource((IEnumerable<object>)ViewBag.datasource)
 .AllowPaging(true)    /*Paging Enabled*/
 .EditSettings(edit => { edit.AllowEditing().AllowAdding().AllowDeleting().EditMode(EditMode.InlineFormTemplate).InlineFormTemplateID("#CustomerForm"); })
.ToolbarSettings(toolbar =>
 {
     toolbar.ShowToolbar().ToolbarItems(items =>
     {
         items.AddTool(ToolBarItems.Add);
         items.AddTool(ToolBarItems.Edit);
         items.AddTool(ToolBarItems.Delete);
         items.AddTool(ToolBarItems.Update);
         items.AddTool(ToolBarItems.Cancel);
     });
 })
 .Columns(col =>
  {
      col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).Width(100).Add();
      col.Field("CustomerID").HeaderText("Customer ID").Width(100).Add();
      col.Field("EmployeeID").HeaderText("Employee ID").Width(100).Add();
  })
 .ClientSideEvents(eve => { eve.ActionComplete("complete").ActionBegin("begin"); }) )

 

[CS]
 
namespace SyncfusionMvcApplication121.Controllers
{
    public class GridController : Controller
    {
        public ActionResult GridFeatures()
        {
            IEnumerable DataSource = new NorthwindDataContext().OrdersViews.ToList();
            ViewBag.datasource = DataSource;
            return View();
        }

 

 

CORE

<ej-grid id="OrdersGrid" allow-paging="true" datasource="ViewBag.dataSource" action-begin="begin" action-complete="complete" >
    <e-edit-settings allow-adding="true" allow-editing="true" allow-deleting="true" edit-mode="InlineFormTemplate" inline-form-template-id="#CustomerForm"></e-edit-settings>
    <e-toolbar-settings show-toolbar="true" toolbar-items="@(new List<string>() { "add","edit","delete","update","cancel" })"></e-toolbar-settings>
    <e-columns>
        <e-column field="OrderID" header-text="Order ID" is-primary-key="true" width="100"></e-column>
        <e-column field="CustomerID" header-text="Customer ID" width="100"></e-column>
        <e-column field="EmployeeID" header-text="Employee ID" width="100"></e-column>
    </e-columns>
</ej-grid>

 

[CS]
 
namespace WebApplication1.Controllers
{
    public class HomeController : Controller
    {
        private NORTHWNDContext _context;
        public HomeController(NORTHWNDContext context)
        {
            _context = context;
        }
        public IActionResult Index()
        {
            ViewBag.dataSource = _context.Orders.Take(100).ToList();
return View();
        }
     }
 }

 

Angular

<ej-grid id="OrdersGrid" [dataSource]="gridData" [allowPaging]="true" [toolbarSettings]="toolbarItems" [editSettings]="editSettings" (actionBegin)="begin($event)" (actionComplete)="complete($event)" > 
   <e-columns>
        <e-column field="OrderID" headertext="Order ID" [isPrimaryKey] ="true" width="100"></e-column>
        <e-column field="CustomerID" headertext="Customer ID" width="100"></e-column>
        <e-column field="EmployeeID" headertext="Employee ID" width="100"></e-column>
    </e-columns>
</ej-grid>

 

TS

export class AppComponent {   
     public toolbarItems;
     public editSettings;
     public gridData: any;
 
constructor() {     
     this.gridData = (window as any).gridData;
     this.editSettings = { allowEditing: true, allowAdding: true, allowDeleting: true, editMode: ej.Grid.EditMode.InlineTemplateForm, inlineFormTemplateID:"#CustomerForm" };
     this.toolbarItems = { showToolbar : true, toolbarItems : ["add", "edit", "delete", "update", "cancel"]};           
     }
     begin(args: any) { 
        if (args.requestType == "save") {
                var uploadObj= $('#UploadInput').ejUploadbox("instance");
                uploadObj.upload();
        }   
     }
     complete(args: any){
        if ((args.requestType == "beginedit" || args.requestType == "add")) {
                $('#UploadInput').ejUploadbox({
                    saveUrl: "/saveFiles.ashx",
                    showFileDetails: false,
                    fileSelect : "select",
                });
         }
     }
}

 

Index.html

 

function select(args) {

            var filename = args.files[0].name;

            $("#imageName").html(filename);

        }

 

 

2. Defining inlineForm template for editing.

 

<script type="text/template" id="CustomerForm">
        <b>Order Details</b>
        <table cellspacing="10">
            <tr>
                <td style="text-align: right;">Order ID
                </td>
                <td style="text-align: left">
                    <input id="OrderID" name="OrderID" value="{{: OrderID}}" disabled="disabled"
                        class="e-field e-ejinputtext valid e-disable" style="text-align: right; width: 116px; height: 28px" />
                </td>
                <td style="text-align: right;">Customer ID
                </td>
                <td style="text-align: left">
                    <input id="CustomerID" name="CustomerID" value="{{:CustomerID}}" class="e-field e-ejinputtext valid"
                        style="width: 116px; height: 28px; text-align: left!important" />
                </td>
            </tr>
            <tr>
                <td style="text-align: right">Picture
                </td>
                <td style="text-align: left">               
                    <div id="UploadInput"></div>
                    <p id="imageName"></p>
                </td>
 
            </tr>
        </table>
    </script>

 

3. ClientSide events for rendering the ejUploadBox and saving the image files.

 

    <script type="text/javascript">
        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 uploadObj = $('#UploadInput').ejUploadbox("instance");
                uploadObj.upload();
            }
        }
        function select(args) {
            var filename = args.files[0].name;
            $("#imageName").html(filename);
        }
    </script>

 

 

Result:

ASP.NET WebForms grid output

 

Note

A new version of Essential Studio for ASP.NET is available. Versions prior to the release of Essential Studio 2014, Volume 2 will now be referred to as a classic versions.The new ASP.NET suite is powered by Essential Studio for JavaScript providing client-side rendering of HTML 5-JavaScript controls, offering better performance, and better support for touch interactivity. The new version includes all the features of the old version, so migration is easy.

The Classic controls can be used in existing projects; however, if you are starting a new project, we recommend using the latest version of Essential Studio for ASP.NET. Although Syncfusion will continue to support all Classic Versions, we are happy to assist you in migrating to the newest edition.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls. If you have any queries or require clarifications, please let us know in the comments section below.

You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied