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. Image for the cookie policy date

Assign Value to DropDown

Hi Syncfusion support

I have the issues regarding the dropdown. My problem is
a. when i'm using this belows code

 <ej-drop-down-list id="GenderList" datasource="ViewBag.datasourceGender" value="10">
                                    <e-drop-down-list-fields text="GenderName" value="GenderId" />

i able to set dropdown based on the value (image a)


when i'm using this code whisch viewbag.genderid has been set in controller, nothing happen (image b)

 <ej-drop-down-list id="GenderList" datasource="ViewBag.datasourceGender" value="viewbag.genderid">
                                    <e-drop-down-list-fields text="GenderName" value="GenderId" />

can you advice on this matters, thanks for the support

Attachment: syncfusion_support_f67f774c.rar

2 Replies

HA haryzad September 11, 2017 02:58 PM UTC

Hi Syncfusion support,

Thanks for the help, currently i'm using the alternative by pass the value through the model as below and can be used for now

<ej-drop-down-list id="GenderList" datasource="ViewBag.datasourceGender" value= "@Model.GenderId">

                                    <e-drop-down-list-fields text="GenderName" value="GenderId" />


KR Keerthana Rajendran Syncfusion Team September 12, 2017 12:37 PM UTC

Hi Haryzad, 
Thank you for contacting  Syncfusion support. 
Yes, you can set the selected value through model by using Value property as mentioned in your update. You can also pass it through ViewBag using value property as shown in the below code 
<ej-drop-down-list  id="GenderList" datasource="(IEnumerable<WebApplication1.Controllers.SelectListItem>)ViewBag.dataSourceGender" value=@ViewBag.Value> 
        <e-drop-down-list-fields text="GenderName" value="GenderId" /> 
public IActionResult Index() 
            GenderList.Add(new SelectListItem { GenderId = 0 , GenderName ="Male"}); 
            GenderList.Add(new SelectListItem { GenderId = 1, GenderName = "Female" }); 
            ViewBag.dataSourceGender = GenderList; 
            ViewBag.Value = 1; 
            return View(); 
We have attached a sample for reference. Please download the sample from  

Live Chat Icon For mobile
Up arrow icon