MultiCombo not returning any selected items

  1. #1

    MultiCombo not returning any selected items

    Hi Ext.NET,
    In Page_Load i am filling MultiCombo control and selecting all the items by using MultiCombo.SelectAll() method. After this need to do another opearation based on the items selected in MultiCombo.
    But its not returning any values in SelectedItems property even MultiCombo.Items also empty in the same event.

    After completing loading if i refresh the page its working fine.

    How to get the selected item values in pageload itself?

    ASPX Code
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Sample.WebForm1" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server">
        </ext:ResourceManager>
        <div>
            <ext:MultiCombo ID="MultiCombo" runat="server" DisplayField="State"
                ValueField="StateID">
                <Store>
                    <ext:Store ID="storeMultiCombo" runat="server">
                        <Reader>
                            <ext:JsonReader IDProperty="StateID">
                                <Fields>
                                    <ext:RecordField Name="StateID" />
                                    <ext:RecordField Name="State" />
                                </Fields>
                            </ext:JsonReader>
                        </Reader>
                    </ext:Store>
                </Store>
            </ext:MultiCombo>
        </div>
        </form>
    </body>
    </html>

    CODE BEHIND
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    namespace Sample
    {
     public partial class WebForm1 : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                List<States> states = new List<States>();
                states.Add(new States { State = "State1", StateID = 1 });
                states.Add(new States { State = "State2", StateID = 2 });
                states.Add(new States { State = "State3", StateID = 3 });
    
                this.MultiCombo.GetStore().DataSource = states;
                this.MultiCombo.GetStore().DataBind();
    
                this.MultiCombo.SelectAll();
    
                int n = this.MultiCombo.SelectedItems.Count; // returns 0
                int m = this.MultiCombo.Items.Count; // returns 0
            }
        }
    
        public class States
        {
            public string State
            {
                get;
                set;
            }
            public int StateID
            {
                get;
                set;
            }
        }
    }
  2. #2
    Hi,

    SelectAll just generates for selecting items on the client side, it doesn't select any items in the server side
    SelectedItems is updated when you submit from from the client (directevent,directmethod or postback)

    Just add button with direct event, click on it and you will see selected items on the server side
    Also I suggest to wrap code in the page load by 'if(!X.IsAjaxRequest){...}'
    Vladimir Shcheglov
    Sr. Developer
  3. #3
    Quote Originally Posted by Vladimir View Post
    Hi,

    SelectAll just generates for selecting items on the client side, it doesn't select any items in the server side
    SelectedItems is updated when you submit from from the client (directevent,directmethod or postback)

    Just add button with direct event, click on it and you will see selected items on the server side
    Also I suggest to wrap code in the page load by 'if(!X.IsAjaxRequest){...}'
    Mmm.. I have just followed your suggestion above.. But still not works Vladimir.. :-/
    This is my simple code :
    <ext:Button runat="server" ID="lnkBtnEditUser" Text="Ubah Data Pengguna" Icon="UserEdit">
                                <DirectEvents>
                                    <Click OnEvent="lnkBtnEditUserx_Click" After="UserManagementX.InitializeControl();">
                                        <ExtraParams>
                                            <ext:Parameter Name="ParentGrid" Value="Ext.encode(#{grdPnlUserList}.getRowsValues({selectedOnly : true}))" Mode="Raw" />
                                        </ExtraParams>
                                    </Click>
                                </DirectEvents>
                            </ext:Button>

    protected void lnkBtnEditUserx_Click(object sender, DirectEventArgs e)
    {
    string tmpUserGroupDetail = string.Empty;
                    foreach (DataRow dr in dataUserGroupDetail.Rows) 
                    {
                        var tmp = listGroups.Find(y => y.Value.Equals(dr["GroupId"]));
                        this.multiCmbRoles.SelectedItems.Add(tmp);
                        tmpUserGroupDetail = string.Concat(dr["GroupName"], ",", tmpUserGroupDetail);
                    }
    }
    Last edited by teamsar; Feb 27, 2013 at 5:03 AM.
  4. #4
    Quote Originally Posted by dtamils View Post
    Hi Ext.NET,
    In Page_Load i am filling MultiCombo control and selecting all the items by using MultiCombo.SelectAll() method. After this need to do another opearation based on the items selected in MultiCombo.
    But its not returning any values in SelectedItems property even MultiCombo.Items also empty in the same event.

    After completing loading if i refresh the page its working fine.

    How to get the selected item values in pageload itself?

    ASPX Code
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Sample.WebForm1" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server">
        </ext:ResourceManager>
        <div>
            <ext:MultiCombo ID="MultiCombo" runat="server" DisplayField="State"
                ValueField="StateID">
                <Store>
                    <ext:Store ID="storeMultiCombo" runat="server">
                        <Reader>
                            <ext:JsonReader IDProperty="StateID">
                                <Fields>
                                    <ext:RecordField Name="StateID" />
                                    <ext:RecordField Name="State" />
                                </Fields>
                            </ext:JsonReader>
                        </Reader>
                    </ext:Store>
                </Store>
            </ext:MultiCombo>
        </div>
        </form>
    </body>
    </html>

    CODE BEHIND
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    namespace Sample
    {
     public partial class WebForm1 : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                List<States> states = new List<States>();
                states.Add(new States { State = "State1", StateID = 1 });
                states.Add(new States { State = "State2", StateID = 2 });
                states.Add(new States { State = "State3", StateID = 3 });
    
                this.MultiCombo.GetStore().DataSource = states;
                this.MultiCombo.GetStore().DataBind();
    
                this.MultiCombo.SelectAll();
    
                int n = this.MultiCombo.SelectedItems.Count; // returns 0
                int m = this.MultiCombo.Items.Count; // returns 0
            }
        }
    
        public class States
        {
            public string State
            {
                get;
                set;
            }
            public int StateID
            {
                get;
                set;
            }
        }
    }

    Hey dtamils,

    Have you tried Vladimir suggestion ?? Is it work ?? May you help me to show your successful code ? Thnx
    Last edited by teamsar; Feb 27, 2013 at 5:04 AM.

Similar Threads

  1. Replies: 4
    Last Post: Dec 27, 2011, 4:25 PM
  2. Replies: 0
    Last Post: Sep 19, 2011, 12:11 PM
  3. Replies: 0
    Last Post: Apr 29, 2011, 9:37 PM
  4. Replies: 5
    Last Post: May 27, 2009, 12:59 PM
  5. [CLOSED] Selected Row Value not returning value from RecordID
    By Christopher Istvan in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: May 01, 2009, 11:21 PM

Tags for this Thread

Posting Permissions