check item in listview

Dear,

I am having a list box with check marks which I am binding from code behind using a List <string>.

How can I tick the checkbox for the 1st item (or a specific item from codebehind?

Thanks a lot in advance,
Prasad..




1 Reply

DL Deepa Loganathan Syncfusion Team October 15, 2018 06:20 AM UTC

Hi Prasad Gurla,    
      
Thanks for contacting Syncfusion Support.   
   
You can have the checkbox in Listbox checked on page load by mapping the CheckBy field of the ListBox to the Model property with Boolean Type. Please find the code snippets below.    
   
   
CSHTML:   
   
<div id="container1">   
   
            <p>   
   
                Drag   
            </p>   
   
           @Html.EJ().ListBox("List1").Height("302").AllowDrag(true).AllowDrop(true).AllowMultiSelection(true).Datasource(Model).ShowCheckbox(true).ListBoxFields(df => df.Text("text").CheckBy("check")).ClientSideEvents(evt => evt.Create("setheight"))   
   
   
        </div>   
   
   
CONTROLLER:   
   
public ActionResult Index()   
        {   
            List<SkillSet> skill = new List<SkillSet>();   
            skill.Add(new SkillSet { text = "ASP.NET"check=true });    // set the checkbox field as a Boolean   
            skill.Add(new SkillSet { text = "ActionScript"check=false});   
            skill.Add(new SkillSet { text = "Basic"check = true });   
            :   
            :   
            :   
           return View(skill);   
        }   
   
   
   
   
   
Output:    
   
When the page is loaded, it will be loaded like the below output with fields checked as given in the data source.   
         
   
   
We have also prepared a sample for your reference.   
   
   
   
Regards,   
Deepa L.   


Loader.
Up arrow icon