Search results

Templates in ASP.NET MVC Spreadsheet control

20 Apr 2021 / 1 minute to read

Cell Template is used for adding HTML elements into Spreadsheet. You can add the cell template in spreadsheet by using the template property and specify the address using the address property inside the ranges property. You can customize the Html elements similar to Syncfusion components (TextBox, DropDownList, RadioButton, MultiSelect, DatePicker etc) by using the beforeCellRender event. In this demo, Cell template is applied to C2:C9 and instantiated with Html input components like TextBox, RadioButton, TextArea. You need to bind the events to perform any operations through HTML elements or Syncfusion components. Here, we have added change event in to the MultiSelect control, and we have updated the selected data into the spreadsheet cell through that change event.

The following code example describes the above behavior.

Copied to clipboard
@Html.EJS().Spreadsheet("spreadsheet").ShowRibbon(false).ShowFormulaBar(false).AllowEditing(false).Created("createdHandler").BeforeSelect("beforeSelectHandler").BeforeCellRender("beforeCellRenderHandler").ScrollSettings(scrollSettings =>
   }).Sheets(sheet =>
       sheet.Name("Registration Form").RowCount(40).ColCount(30).ShowGridLines(false).Rows(row =>
           row.Height(55).Cells(cell => cell.Index(1).Value("Interview Registration Form").Style(style =>
           row.Height(45).Cells(cell => cell.Index(1).Value("Name").Add()).Add();
           row.Height(45).Cells(cell => cell.Index(1).Value("Date of Birth:").Add()).Add();
           row.Height(45).Cells(cell => cell.Index(1).Value("Gender:").Add()).Add();
           row.Height(45).Cells(cell => cell.Index(1).Value("Year of Experience:").Add()).Add();
           row.Height(45).Cells(cell => cell.Index(1).Value("Areas of Interest:").Add()).Add();
           row.Height(45).Cells(cell => cell.Index(1).Value("Mobile Number:").Add()).Add();
           row.Height(45).Cells(cell => cell.Index(1).Value("Email:").Add()).Add();
           row.Height(82).Cells(cell => cell.Index(1).Value("Address:").Add()).Add();
       }).Columns(column =>
       }).Ranges(ranges =>
           ranges.Template("<input />").Address("C2:C3").Add();
           ranges.Template("<div><input type='radio' name='gender' value='male' /><input type='radio' name='gender' value='female'/></div>").Address("C4").Add();
           ranges.Template("<input />").Address("C5:C8").Add();
           ranges.Template("<textarea rows='3'/>").Address("C9").Add();
           ranges.Template("<button class='e-btn e-flat' style='float:right'>Add</button>").Address("C11").Add();

    function createdHandler() {
        //Applies format to specified range
        this.cellFormat({ fontWeight: 'bold' }, 'B2:B9');
    function beforeSelectHandler(args) {
        //Prevents selection
        args.cancel = true;
    function beforeCellRenderHandler(args) {
        //Initializing input components before cell rendering
        if (this.activeSheetIndex === 0) {
            var target = args.element.firstElementChild;
            switch (args.address) {
                case 'B1':
                    args.element.colSpan = 2;
                case 'C2':
                    new ej.inputs.TextBox({ placeholder: 'Name' }, target);
                case 'C3':
                    new ej.calendars.DatePicker({ placeholder: 'DOB', }, target);
                case 'C4':
                    new ej.buttons.RadioButton({ label: 'Male' }, args.element.firstElementChild.firstElementChild);
                    new ej.buttons.RadioButton({ label: 'Female' }, args.element.firstElementChild.lastElementChild);
                case 'C5':
                    var experience =  ['0 - 1 year', '1 - 3 years', '3 - 5 years', '5 - 10 years'];
                    new ej.dropdowns.DropDownList({
                        placeholder: 'Experience',
                        dataSource: experience
                    }, target);
                case 'C6':
                    var languages = ['JAVA', 'C#', 'SQL'];
                    new ej.dropdowns.MultiSelect({
                        showClearButton: false,
                        placeholder: 'Areas of Interest',
                        dataSource: languages,
                        change: function(evt) {
                            if (args.cell) {
                                args.cell.value = evt.value.toString();
                            } else {
                                var range = ej.spreadsheet.getRangeIndexes(evt.address);
                                spreadsheet.sheets[spreadsheet.activeSheetIndex].rows[range[0]].cells[range[1]] = { value: evt.value.toString() };
                    }, target);
                case 'C7':
                    new ej.inputs.TextBox({
                        placeholder: 'Mobile Number'
                    }, target);
                case 'C8':
                    new ej.inputs.TextBox({
                        placeholder: 'Email'
                    }, target);
                case 'C9':
                    new ej.inputs.TextBox(null, target);

    .e-spreadsheet .e-tab .e-tab-text {
        display: inherit;

    .e-spreadsheet .e-cell .e-radio-wrapper {
        margin: 5px;

    .e-spreadsheet .e-cell .e-radio-wrapper:first-child {
            margin-left: 0;

    .e-spreadsheet .e-cell .e-radio + label .e-label {
        color: rgba(0, 0, 0, 0.87);

See Also