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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Assign Value to DropDown

Thread ID:

Created:

Updated:

Platform:

Replies:

132598 Sep 11,2017 02:36 PM UTC Sep 12,2017 12:37 PM UTC ASP.NET Core 2
loading
Tags: DropDownList
haryzad
Asked On September 11, 2017 02:36 PM UTC

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" />
                                </ej-drop-down-list>

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

but

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" />
                                </ej-drop-down-list>

can you advice on this matters, thanks for the support



Attachment: syncfusion_support_f67f774c.rar

haryzad
Replied On 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" />

                                </ej-drop-down-list>



Keerthana Rajendran [Syncfusion]
Replied On 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" /> 
 
    </ej-drop-down-list> 
 
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  
 
 
Regards, 
Keerthana 


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

;