How to set set selected items on MultiCombo which requires remote data once shown

  1. #1

    How to set set selected items on MultiCombo which requires remote data once shown

    Hi!
    I write a multicombo which dynamically loads data from backend.
    But I don't know how to set all the combo box items selected on start up.
    Any one who can tell me how ?
    Thanks!

    @using Ext.Net;
    @using Ext.Net.MVC;
    @using System.Web.UI.WebControls;
    
    @{
        Layout = null;
        var x = Html.X();
    }
    @(x.ResourceManager().Theme(Theme.Default))
    
    @(
    x.MultiCombo().ID("combo1").Editable(false).Name("project").FieldLabel("Versions").Store(
        x.Store().Proxy(
            x.AjaxProxy().Url("/Project/GetProjectVersions2").Reader(x.JsonReader().Root("data"))
        ).Model(x.Model().Fields(
                new ModelField("id"),
                new ModelField("name")
            )
        )
    ).DisplayField("name").ValueField("id")
    )
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using MvcApplication2.Models;
    using Ext.Net;
    using Ext.Net.MVC;
    
    namespace MvcApplication2.Controllers
    {
        public class ProjectController : Controller
        {
            public ActionResult GetProjectVersions2()
            {
                List<object> data = new List<object>();
                data.Add(new { id = "value1", name = "Name1" });
                data.Add(new { id = "value2", name = "Name2" });
                return this.Store(data);
            }
        }
    }
  2. #2

    Found Solution

    Oh this is a stupid question.
    I found the solution , quite simple. Call the getSampleVersions method in cshtml directly, or put the data in Controller's ViewData and push it to the view to render.
    please mark as closed :-)
    var versions=ProjectPeriodModel.getSampleVersions();
    foreach(var version in versions)
    {
        combo2.Items.Add(new Ext.Net.ListItem() { Text = version.name, Value = version.id });
        combo2.SelectedItems.Add(new Ext.Net.ListItem() { Value=version.id});
    }
    combo2.UpdateSelectedItems();

Similar Threads

  1. [CLOSED] Multicombo created dynamically not showing selected items
    By rnachman in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Sep 10, 2013, 11:38 AM
  2. Replies: 3
    Last Post: Jun 25, 2013, 4:45 PM
  3. MultiCombo not returning any selected items
    By dtamils in forum 1.x Help
    Replies: 3
    Last Post: Feb 27, 2013, 3:56 AM
  4. Replies: 4
    Last Post: Dec 27, 2011, 3:25 PM
  5. Replies: 0
    Last Post: Sep 19, 2011, 11:11 AM

Tags for this Thread

Posting Permissions