MultiCombo: Set Multiple Selected Values in Code Behind

  1. #1

    MultiCombo: Set Multiple Selected Values in Code Behind

    Problem: I select a row in a Grid that should populate a form. I am loading the MultiCombo from a store (That is working fine). I cannot preselect multiple items. LoadFundingSources() below loads the items into the MultiCombo Box. strFunding below in the RowSelection event below is a comma delimited string of numeric values.

    ASPX:

    <ext:MultiCombo ID="mcbFundingSource" runat="server" FieldLabel="Funding Source" Name="FundingSourceID"
    	DisplayField="FundingSource"
    	ValueField="FundingSource"
    	EmptyText="Select Funding Source..."
    	Selectable="true"
    	QueryMode="Local"
    	ForceSelection="true"
    	TriggerAction="All"
    	SelectOnFocus="true"
    	AllowBlank="true">
    	<Store>
    		<ext:Store ID="StoreFundingSources" runat="server">
    			<Model>
    				<ext:Model ID="Model17" runat="server">
    					<Fields>
    						<ext:ModelField Name="FundingSource" />
    						<ext:ModelField Name="FundingSourceID" />
    					</Fields>
    				</ext:Model>
    			</Model>
    		</ext:Store>
    	</Store>
    </ext:MultiCombo>
    Code Behind:

    private void LoadFundingSources()        
    {
    	EarlyChildhoodCouncilData.FundingSource objItems = new EarlyChildhoodCouncilData.FundingSource();
    	DataView dv = objItems.GetList().DefaultView;
    	dv.RowFilter = "Active='" + true + "'";
    	dv.Sort = "SortOrder";
    	StoreFundingSources.DataSource = dv;
    	StoreFundingSources.DataBind();
    }
    
    public void RowSelectCase(object sender, Ext.Net.DirectEventArgs e)
    {
    	string caseID = e.ExtraParams["CaseID"];
    	EarlyChildhoodCouncilData.Case objCase = new EarlyChildhoodCouncilData.Case(int.Parse(caseID));
    
    	LoadFundingSources();
    
    	this.FormPanel1.SetValues(new
    	{
    		objCase.CaseID,
    		objCase.ReferralSourceID
    		
    	});
    
    	mcbFundingSource.SetValue(1);  //This only selects one value
    
       String[] strFunding = objCase.FundingSource.Split(',');
       for (Int32 x = 0; x < strFunding.Length; x++)
       {
    		  mcbFundingSource.SetValue(strFunding[x]);  //This only loads the last item
       }
    }
    Last edited by Baidaly; Dec 15, 2012 at 1:00 AM. Reason: Please, use [CODE] tag
  2. #2
    Hello!

    To preselect many values in MultiCombo use SelectedItems:

    <%@ Page Language="C#" AutoEventWireup="true"  %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs args)
        {
            MultiSelect1.SelectedItems.Add(new Ext.Net.ListItem("1"));
            MultiSelect1.SelectedItems.Add(new Ext.Net.ListItem("2"));
        }
    </script>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>Ext.NET Examples</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            
            <ext:Panel runat="server" Title="MultiSelects" Width="660" Layout="HBoxLayout">            
                <Items>
                    <ext:Panel 
                        runat="server" 
                        Border="false" 
                        Height="260" 
                        Flex="1" 
                        Layout="Fit" 
                        BodyPadding="5">
                        <Items>
                            <ext:MultiSelect ID="MultiSelect1" runat="server" ListTitle="MultiSelect1">
                                <Items>
                                    <ext:ListItem Text="Item 1" Value="1" />
                                    <ext:ListItem Text="Item 2" Value="2" />
                                    <ext:ListItem Text="Item 3" Value="3" />
                                    <ext:ListItem Text="Item 4" Value="4" />
                                    <ext:ListItem Text="Item 5" Value="5" />
                                </Items>
                            </ext:MultiSelect>      
                        </Items>
                    </ext:Panel>                                                             
                </Items>
            </ext:Panel>
        </form>
    </body>
    </html>
  3. #3

    Still no go.

    I have simplified my example on a new page to make it is easier to diagnose.

    ASPX:

    <ext:ResourceManager runat="server" />
    <ext:Panel runat="server" Title="MultiSelects" Width="660" Layout="HBoxLayout">
    <Items>
    <ext:Panel runat="server" Border="false" Height="260" Flex="1" Layout="Fit" BodyPadding="5">
    <Items>
    <ext:MultiCombo ID="MultiCombo1" runat="server" FieldLabel="Funding Source" Name="FundingSourceID"
    DisplayField="FundingSource"
    ValueField="FundingSourceID">
    <Store>
    <ext:Store ID="StoreFundingSources" runat="server">
    <Model>
    <ext:Model ID="Model17" runat="server">
    <Fields>
    <ext:ModelField Name="FundingSource" />
    <ext:ModelField Name="FundingSourceID" />
    </Fields>
    </ext:Model>
    </Model>
    </ext:Store>
    </Store>
    </ext:MultiCombo>
    </Items>
    </ext:Panel>
    </Items>
    </ext:Panel>

    CODE BEHIND:

    protected void Page_Load(object sender, EventArgs e)
    {
    EarlyChildhoodCouncilData.FundingSource objItems = new EarlyChildhoodCouncilData.FundingSource();
    DataView dv = objItems.GetList().DefaultView;
    dv.RowFilter = "Active='" + true + "'";
    dv.Sort = "SortOrder";
    StoreFundingSources.DataSource = dv;
    StoreFundingSources.DataBind();

    MultiCombo1.SelectedItems.Add(new Ext.Net.ListItem("1"));
    MultiCombo1.SelectedItems.Add(new Ext.Net.ListItem("2"));
    }

    VIEW SOURCE:

    Ext.net.ResourceMgr.init({id:"ctl00$ContentPlaceHo lder1$ctl00",aspForm:"Form1"});Ext.onReady(functio n(){Ext.create("Ext.button.Button",{id:"TopMenu1_B utton1",renderTo:"App.TopMenu1_Button1_Container", menu:{id:"TopMenu1_Menu2",xtype:"menu",items:[{id:"TopMenu1_MenuItem4",href:"AdminHome.aspx",tex t:"Welcome"},{id:"TopMenu1_MenuItem5",href:"/Default.asp",hrefTarget:"_blank",text:"Preview Website"},{id:"TopMenu1_MenuItem6",href:"Logout.as px",text:"Logout"}]},text:"Admin Home"});Ext.create("Ext.panel.Panel",{renderTo:"Ap p.ContentPlaceHolder1_ctl01_Container",width:660,i tems:[{border:false,height:260,flex:1,items:[{id:"ContentPlaceHolder1_MultiCombo1",xtype:"netmu lticombo",fieldLabel:"Funding Source",name:"FundingSourceID",selectedItems:[{text:"1",value:"1"},{text:"2",value:"2"}],displayField:"FundingSource",multiSelect:true,tri ggerAction:"all",valueField:"FundingSourceID",stor e:{model:Ext.define("App.ContentPlaceHolder1_Model 17", {extend: "Ext.data.Model", fields:[{name:"FundingSource"},{name:"FundingSourceID"}] }),storeId:"ContentPlaceHolder1_StoreFundingSource s",autoLoad:true,proxy:{data:[{"FundingSourceID":5,"FundingSource":"NIC"},{"Fund ingSourceID":1,"FundingSource":"VPK"},{"FundingSou rceID":4,"FundingSource":"Private Pay"},{"FundingSourceID":6,"FundingSource":"Other" }], type: 'memory'}}}],layout:"fit",bodyPadding:5}],layout:"hbox",title:"MultiSelects"});});
    Last edited by ecotto; Dec 15, 2012 at 12:05 PM.
  4. #4
    Please, use CODE tag and try to provide simplified examples without dependencies on databases.

    Plese, review following threads:
    http://forums.ext.net/showthread.php?3440
    http://forums.ext.net/showthread.php?10205

    About your problem. This code means:

    MultiCombo1.SelectedItems.Add(new Ext.Net.ListItem("1"));
    MultiCombo1.SelectedItems.Add(new Ext.Net.ListItem("2"));
    that you should substitute '1' and '2' with your values from DataBase and doesn't mean indexes

Similar Threads

  1. Replies: 1
    Last Post: Mar 11, 2012, 3:03 AM
  2. Replies: 5
    Last Post: Jun 08, 2011, 11:19 AM
  3. Replies: 1
    Last Post: Jan 31, 2011, 7:45 AM
  4. How to get selected values form grid in code behind
    By harshad.jadhav in forum 1.x Help
    Replies: 1
    Last Post: Jul 12, 2010, 8:51 AM

Tags for this Thread

Posting Permissions