We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

How to check checkbox on dialog template based upon a grid value

Thread ID:

Created:

Updated:

Platform:

Replies:

120650 Sep 30,2015 09:03 AM Jun 29,2016 12:01 AM ASP.NET MVC 3
loading
Tags: Grid
Fabrizio Borgione
Asked On September 30, 2015 09:03 AM

Hi

I have a grid with e checkbox column

                        @(Html.EJ().Grid<MyProject.Model.ViewModels.MyViewModel>("MyGrid")
                            .EditSettings(edit =>
                                edit.AllowEditing()
                                .AllowAdding()
                                .AllowDeleting()
                                .EditMode(EditMode.DialogTemplate)
                                .DialogEditorTemplateID("#editTemplate")
                                )
                            .AllowFiltering()
                            .AllowPaging()
                            .AllowSorting()
                            .AllowTextWrap()
                            .Locale("it-IT")
                            .FilterSettings(filter => { filter.FilterType(FilterType.Excel); })
                            .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("Id").IsPrimaryKey(true).Visible(false).Add();
                                col.Field("Name").HeaderText("Name").HeaderTextAlign(TextAlign.Center).EditType(EditingType.String).ValidationRules(v => v.AddRule("required", true)).Add();
                                col.Field("Active").HeaderText("Active").TextAlign(TextAlign.Center).HeaderTextAlign(TextAlign.Center).EditType(EditingType.Boolean).Add();
                            })
                        )

I use a dialog template to edit data

<script type="text/template" id="editTemplate">
    <table cellspacing="10">
        <tr>
            <td style="text-align:right;">Name:</td>
            <td style="text-align:left;">
                <input id="Name" name="Name" value="{{: Name}}" class="e-field e-ejinputtext valid" style="width:200px;" />
            </td>
            <td>
                <input id="Active" name="Active" value="{{: Active}}" type="checkbox" class="e-field e-ejcheckbox valid" style="width:20px;" />
            </td>
            <td style="text-align:left;">Active</td>
        </tr>
    </table>
</script>

In execution, when i open the dialog to edit data the checkbox is never checked, even if the column in the grid is checked.
What am i doing wrong?
Thank you

Balaji Marimuthu [Syncfusion]
Replied On October 1, 2015 05:53 AM

Hi Fabrizio, 

Thanks for contacting Syncfusion support.

To display the checkbox while editing, please render the template as follows,




<script type="text/template" id="editTemplate">

    <table cellspacing="10">

        <tr>

            <td style="text-align:right;">Name:</td>

            <td style="text-align:left;">

                <input id="Name" name="Name" value="{{: Name}}" class="e-field e-ejinputtext valid" style="width:200px;" />

            </td>

            <td>

                {{if Active}}

                <input id="Active" name="Active" type="checkbox" class="e-field e-ejcheckbox valid" checked="checkbox" style="width:20px;" />

                {{else}}

                <input id="Active" name="Active" type="checkbox" class="e-field e-ejcheckbox valid" style="width:20px;" />

                {{/if}}

            </td>

            <td style="text-align:left;">Active</td>

        </tr>

    </table>

</script>




Please refer to the following sample, 
MvcEJGrid

Regards,
Balaji Marimuthu


Ismail Karakaya
Replied On June 28, 2016 03:17 PM

 
you can use "checked" instead of "value ". It worked for me

<input id="Active" name="Active" value="{{: Active}}" type="checkbox" class="e-field e-ejcheckbox valid" style="width:20px;" />

<input id="Active" name="Active" checked="{{: Active}}" type="checkbox" class="e-field e-ejcheckbox valid" style="width:20px;" />

Karthick Kuppusamy [Syncfusion]
Replied On June 29, 2016 12:01 AM

Hi Fabrizio, 
 
Thanks for the update. 
 
We are happy to hear that your requirement is achieved. 
 
Regards, 
K.Karthick. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;