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 do I use data binding in GenericDropDown

Thread ID:

Created:

Updated:

Platform:

Replies:

112530 Sep 26,2013 12:57 PM Oct 3,2013 02:44 AM ASP.NET MVC (Classic) 1
loading
Tags: Tools
Pete
Asked On September 26, 2013 12:57 PM

I have tried following the examples in the documentation but they are too simplistic and not helpful.  There is no example and source available on the website.  Can you please post a clear example that uses MVC 4, populating the drop-down with a list of items in the controller.  The items just need to have an int ID and a string NAME.  The strings and IDs come from a database, so I cannot manually write out the list in code.

I have tried putting the list in ViewData in the controller and using:
@{ Html.Syncfusion().GenericDropDown("SecondPhaseID").Render(); }

I have tried using GenericDropDownFields and GenericDropDownModel to make a model that is put in ViewData and using:
@(Html.Syncfusion().GenericDropDown("MyGenericDropDown", ViewData["myGenericDropDownModel"]))

and every variation off of that that I can think of.  When I run the page, the control does not appear.  I can put a breakpoint, but nothing shows on the page.  If I manually create a list in the control and fill the Items collection, then the control will appear.  But using my code, the Items array has a count of 0, but the DataSource has the correct list of items.  I do not know if that is correct behavior or not because there is almost no documentation that I can find.  Please help me with a very detailed example, thank you.







Gurunathan A [Syncfusion]
Replied On October 3, 2013 02:44 AM

Hi Pete,

 

Thanks for contacting Syncfusion support.

 

Your requirement of Generic DropDown with Databinding option can be achieved by setting the field of GenericDropDownField related to generic list and then assign the Datasource and bind the fields to GenericDropDownModel. Hence forth you can get the bind values in View page.

 

<code>

[Controller]

 

public ActionResult ToolsFeatures()

        {

 

            ViewData["DropdownData"] = new Student1DataContext().Student1;

 

            GenericDropDownFields genericdropdownFields = new GenericDropDownFields()

 

            {

 

                Id = "UniversityCode",

 

                Text = "Title"               

 

            };

 

            GenericDropDownModel genericdropdownModel = new GenericDropDownModel()

 

            {

 

                DataSource =(System.Collections.IEnumerable)ViewData["DropdownData"],  //Bindling Datasource with Generic list

 

                BindTo = genericdropdownFields,                                        //Binding Items with Generic DropDown fields

 

                ClientSideOnClick = "ClientSideOnClick",                               //Binding ClientSideOnClick event

 

            };

          

         

            ViewData["myGenericDropDownModel"] = genericdropdownModel;                 //Binding dynamically created model to Viewdata

 

            return View();

                          

           }      

        

    }   

 

</code>

 

We have provided information about Generic DropDown with Data binding concept in our documentation. The documentation is available in following link.

 

http://help.syncfusion.com/ug/asp.net%20mvc/tools/default.htm#!documents/databinding.htm

 

We have also prepared a simple sample to explicit this behavior. It can be downloaded from below given link

 

Generic_DB.zip

 

Warm Regards,

Gurunathan


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.

;