render selected item on load using ItemTemplate, ValueTemplate method

Hello, I need help to render the selected item in the dropdownlist using templated html
below is my code for the dropdown component

@Html.EJS().DropDownList("CSTNameUpdate").DataSource(ds => ds.Url(@Url.Action("DropDownListCSTName", "EngineeringEquipment"))).Placeholder("Select CST").Fields(new Syncfusion.EJ2.DropDowns.DropDownListFieldSettings { Value = "Key" }).ItemTemplate(

                  "<div style=\"margin-top:3px\" >${Key}-${COLUMN_NAME}</div>").ActionFailure("onCSTFail").ValueTemplate(

                  "<div style=\"width:100%;height:100%;\"><div class=\"name\">${Key}-${COLUMN_NAME}</div></div>").Change("CSTNameOnChangeUpdate").FloatLabelType(Syncfusion.EJ2.Inputs.FloatLabelType.Always).Render()

AND THIS IS my datasource:

I cannot seem to find the solution, thankyou


5 Replies 1 reply marked as answer

UD UdhayaKumar Duraisamy Syncfusion Team August 4, 2022 04:14 PM UTC

Hi Bernadus,


As per requirement we have created a sample using an item template and value template and shared the sample link below for your reference. Please refer to the below documentation and the online demo sample for more information.


Sample : https://www.syncfusion.com/downloads/support/directtrac/general/ze/MVC_DDL_URL_sample-552102750


Documentation : https://ej2.syncfusion.com/aspnetmvc/documentation/drop-down-list/templates


Online Demo : https://ej2.syncfusion.com/aspnetmvc/DropDownList/Template#/bootstrap5


Regards,

Udhaya Kumar D




BR Bernadus Rangga Kresna Waskita August 12, 2022 02:09 AM UTC

I think this sample is not what I asked for.
I need the drop downlist value option is already choosen based on Model...

so its like edit form, the drop down should be already selected and so, user know what the selected value before he/she want to change it.. Thanks



SP Sureshkumar P Syncfusion Team August 12, 2022 06:13 AM UTC

Hi Bernadus,

We suggest you use for components when initializing the component with model value and validate like edit form components.

To know more about the for component. Please refer to the online demo here: https://ej2.syncfusion.com/aspnetmvc/DropDownList/DropdownlistFor#/bootstrap5

Regards,

Sureshkumar P


Marked as answer

BR Bernadus Rangga Kresna Waskita August 29, 2022 07:46 AM UTC

thankyouu




DR Deepak Ramakrishnan Syncfusion Team August 30, 2022 07:46 AM UTC

Hi Bernadus,


Hope that the previously provided solution fulfills your requirement . Kindly contact us if need more assistance on this.


Thanks,

Deepak R.


Loader.
Up arrow icon