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.
Syncfusion Feedback

Specifying data source/options list for CellEditType. DropdownEdit column

Thread ID:

Created:

Updated:

Platform:

Replies:

104103 Jun 21,2012 11:07 AM UTC Sep 17,2012 09:29 AM UTC ASP.NET MVC (Classic) 4
loading
Tags: Grid
Mohit Jain
Asked On June 21, 2012 11:07 AM UTC

Hi,

I am using CellEditType. DropdownEdit edit mode in manual excel like editing with JSON action mode.

My code looks exactly as given in samples on your site. Now when I run the app I get following Javascript error - 'grid.jsonModeMgr._jsonDataAndOption.FIELDNAME_Options' is null or not an object.

This is because it didn't get the drop down list options.

In all of your code samples I didn't find any way to specify any way for specifying data source.

Please let me know how can I supply master list for adding new row for drop down columns.

Thanks.

 


Eswari S [Syncfusion]
Replied On June 22, 2012 09:20 AM UTC

Hi Mohit,

Thank you for using Syncfusion products.

Your requirement of displaying dropdownlist values in edit form can be achieved by handling ajax post . The datas of the dropdownlist values can be added by handling OnCellEdit event and setting the dropdown selected value to the grid can be achieved by handling OnActionSuccess Event. Please refer to the code-snippets below.

Step #1: Set the Celledittype as DropDownEdit in grid column and handle the events for updating drop down.

 

 <%=Html.Syncfusion().Grid<EditableOrder>("SampleGrid")
                .Datasource(Model)
                .Caption("Orders")
                .Column(col =>
                {
                    col.Add(c => c.ShipCountry).CellEditType(CellEditType.DropdownEdit);
                                             . . .  .                                                                                                                                                                                                                                                                                                                             
                })
.ClientSideEvents(events=>{ 
events.OnCellEdit('SetdropDownData'); //Updating dropdown values
events.OnActionSuccess('GetdropDownData'); //Obtaining the dropdownlist values

})

%>



Step #2:
Handling Ajax post for updating Dropdown values


Script as follows:

<script type='text/javascript'>
var dropDownOptions = null;
function GetdropDownData(sender, args) {
$.ajax({
type: 'POST',
url: 'Home/GetCountries',
dataType: 'json',
success: function (data) {
dropDownOptions = data;

}
});
}
function SetdropDownData(sender, args) {
if (dropDownOptions != null)
UpdateDropDown(dropDownOptions);
}
function UpdateDropDown(data) {
$('#ShipCountry').empty();
$.each(data, function (index, val) {
var optionTag = $('<option></option>');
$(optionTag).val(val.Value).text(val.Text);
$('#ShipCountry').append(optionTag);
});
}

</script>

Step #3: Populate external country list dropdown values.

 

[Controller]


 public IEnumerable<SelectListItem> CountryList

        {

            get

            {

 

                List<SelectListItem> type = new List<SelectListItem>();

                type.Add(new SelectListItem

                {

                    Selected = true,

                    Text = "Switzerland",

                    Value = "Switzerland"

                });

                type.Add(new SelectListItem

                {

 

                    Text = "Brazil",

                    Value = "Brazil"

                });

                type.Add(new SelectListItem

                {

                    Text = "Germany",

                    Value = "Germany"

                });

 

                return type;

            }

        }


        public ActionResult GetCountries()
        {
            return Json(CountryList, JsonRequestBehavior.AllowGet);

        }

For your convenience , we have prepared the sample and the same can be downloaded from the following link:    

 

http://www.syncfusion.com/downloads/Support/DirectTrac/95502/Sample1116395137.zip

 

Please try this and let us know if you have any other queries.                                     

 

Regards,

Eswari.S                                                                                                                                                         

 

 

 


Anthony Ludmilin
Replied On September 14, 2012 09:06 PM UTC

Can you please update the sample for version 10.3.0.43 (the latest). I'm having a trouble running it with the latest version. 

-----------------------------------------------
  <system.web>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="Syncfusion.Core, Version=10.304.0.43, Culture=neutral, PublicKeyToken=632609B4D040F6B4"/>
        <add assembly="Syncfusion.Shared.Mvc, Version=10.344.0.43, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89"/>
        <add assembly="Syncfusion.Grid.Mvc, Version=10.344.0.43, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89"/>
      </assemblies>
    </compilation>

---------------------------------------

Server Error in '/' Application.

[A]System.Web.WebPages.Razor.Configuration.HostSection cannot be cast to [B]System.Web.WebPages.Razor.Configuration.HostSection. Type A originates from 'System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context 'Default' at location 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages.Razor\v4.0_1.0.0.0__31bf3856ad364e35\System.Web.WebPages.Razor.dll'. Type B originates from 'System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context 'Default' at location 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages.Razor\v4.0_2.0.0.0__31bf3856ad364e35\System.Web.WebPages.Razor.dll'.


Anthony Ludmilin
Replied On September 14, 2012 10:26 PM UTC

Additional questions. Can the same approach may be used with:

.ActionMode(ActionMode.Server) ?

.EditMode(GridEditMode.Normal)  ?


Eswari S [Syncfusion]
Replied On September 17, 2012 09:29 AM UTC

Hi Anthony,

 

Thanks for the update.

 

Query #1: Can you please update the sample for version 10.3.0.43 (the latest). I'm having a trouble running it with the latest version. 

 

We have modified the sample for latest version and the same can be downloaded from the following link:

 

http://www.syncfusion.com/downloads/Support/DirectTrac/97663/Sample1201781218.zip

 

We suspect that the cause of the error which you posted would be, MVC4 and MVC3 conflict. Please refer to the following link:

 

http://stackoverflow.com/questions/9384421/installed-mvc-4-beta-now-my-mvc-3-projects-throw-an-error-when-i-rebuild-all

 

Query #2: Additional questions. Can the same approach may be used with: .ActionMode(ActionMode.Server) ? .EditMode(GridEditMode.Normal)  ?

 

We have prepared the sample for your requirement and the same can be downloaded from the following link:

 

http://www.syncfusion.com/downloads/Support/DirectTrac/97663/Sample-Normal Editing-159064718.zip

 

In server mode , for updating dropdown we need to bind the events “OnActionBegin” and “OnActionSuccess”.Please refer to the following code snippets:

 

@{Html.Syncfusion().Grid<EditableOrder>("SampleGrid")

                . . . . . .

                .ClientSideEvents(events =>

                {

                    events.OnActionSuccess("SetdropDownData"); //Updating dropdown values 

 

                    events.OnActionBegin("GetdropDownData"); //Obtaining the dropdownlist values

 

                })}

 

Please try this and let us know if you have any other queries.

 

Regards,

Eswari.S

 

 


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.

Warning Icon 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.Close Icon

;