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
close icon

Check items in listbox on edit view.

I have checked listbox in my edit view like this:

@Html.EJ().ListBox("lstCountry").Width("100%").Datasource((IEnumerable<SelectListItem>)ViewBag.lstCntry).ListBoxFields(lf => lf.Text("Text").Value("Value")).ClientSideEvents(e => e.CheckChange("onCheck")).ShowCheckbox(true).CheckItemsByIndex(Model.country_filter)

but it won't check items based on country_filter field, which is for example, "AT,AU,AZ".

Thanks!
B.



5 Replies

BJ Bernard Jurlina November 20, 2016 03:46 PM UTC

Well, there is other method checkItemsByIndices, but it works with index values also. That's why my example won't work.
My listbox show values from countries list, lstCountry, for example, "AU" - "Australia"; "AT" - "Austria". How can I check items in listbox on edit view if I save "AU,AT" value in database?
That means that Austria and Australia has to be checked on edit.

Thanks!
B.


BJ Bernard Jurlina November 20, 2016 11:10 PM UTC

Ok, I solved it.
In controllers ActionResult Edit I create a list, List<int> lstidx, and find indexes of save country marks with foreach loop....and forward it in ViewBag.
In edit view I use the ListBox like this:

@Html.EJ().ListBox("lstCountry").Width("100%").Datasource((IEnumerable<SelectListItem>)ViewBag.lstCntry).ListBoxFields(lf => lf.Text("Text").Value("Value")).ClientSideEvents(e => e.CheckChange("onCheck")).ShowCheckbox(true).CheckItemsByIndex(ViewBag.lstidx)

and it works.

B.


ES Ezhil S Syncfusion Team November 21, 2016 04:39 AM UTC

Hi Jurlina, 

Thank you for contacting Syncfusion support. 

We are glad that you were able to achieve the requirement. 
 
Please let us know if you need further assistance. 
 
Regards, 
Ezhil S 



MU Muhammad Usman March 31, 2017 05:32 AM UTC

hello sir could you please provide me its implementation i will be very thankfull to you .All i need its controller action implementation
i want to implement it in mvc 5


AP Arun Palaniyandi Syncfusion Team April 3, 2017 06:34 PM UTC

Hi Usman, 
 
Thanks for contacting Syncfusion Support.       
     
We have provided the sample below for your reference. 
 
If the shared sample didn’t meet your requirement, then please get back us more information that will help us provide a prompt solution. 
 
Regards,   
Arun P.   


Loader.
Live Chat Icon For mobile
Up arrow icon