[CLOSED] ComboBox load value

  1. #1

    [CLOSED] ComboBox load value

    Hi all,

    I want to know what is the best way to load the combo from code behind in v.2 .
    In fact, in v.1, I use the following code:

    this.comboBoxCompanies.Value = employee.getCompanyId;
    where employee.getCompanyId is an integer.

    In v.2 , I use the following code:

       this.comboBoxCompanies.SelectedItems.Add(new Ext.Net.ListItem { Value = "" + employee.getCompanyId });
       this.comboBoxCompanies.UpdateSelectedItems();
    The two previous code work good, but I'm wonder if there is a way in v.2 to load data in the same way as in v.1

    Best Regards
    Last edited by Daniil; Dec 25, 2012 at 10:25 AM. Reason: [CLOSED]
  2. #2
    Hi @FpNetWorth,

    Setting .Value in Ext.NET v1 just selects an item, it doesn't load anything.

    It should causes the same effect in Ext.NET v2.

    The requirement is unclear.

    Please provide a working sample for Ext.NET v1. I will try to convert it for Ext.NET v2.
  3. #3
    I would like to list another ways to accomplish it:

    By Index
    comboBoxCompanies.Select(1);
    By Value
    comboBoxCompanies.Select("1");
    By Value
    comboBoxCompanies.SetValue("1");
    By Value
    comboBoxCompanies.SetValueAndFireSelect("1");
    Quote Originally Posted by Daniil View Post
    Setting .Value in Ext.NET v1 just selects an item, it doesn't load anything.
    I agree with you Daniil, but i think that he meant select instead of load. Is that correct @FpNetWorth?
    Last edited by RCN; Dec 21, 2012 at 3:36 PM.
  4. #4
    Probably, you are right, Raphael.

    By setting up a ComboBox's Value property appears to be working.

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                Store store = this.ComboBox1.GetStore();
                store.DataSource = new object[] 
                { 
                    new object[] { 1, "Item 1" },
                    new object[] { 2, "Item 2" },
                    new object[] { 3, "Item 3" }
                };
                store.DataBind();
            }
        }
    
        protected void Select(object sender, DirectEventArgs e)
        {
            this.ComboBox1.Value = 1;
        }
    </script>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>Ext.NET v2 Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            <ext:ComboBox 
                ID="ComboBox1" 
                runat="server" 
                DisplayField="text" 
                ValueField="value">
                <Store>
                    <ext:Store runat="server">
                        <Model>
                            <ext:Model runat="server">
                                <Fields>
                                    <ext:ModelField Name="value" Type="Int" />
                                    <ext:ModelField Name="text" />
                                </Fields>
                            </ext:Model>
                        </Model>
                        <Reader>
                            <ext:ArrayReader />
                        </Reader>
                    </ext:Store>
                </Store>
            </ext:ComboBox>
            <ext:Button runat="server" Text="Select" OnDirectClick="Select" />
        </form>
    </body>
    </html>
  5. #5
    Quote Originally Posted by RCN View Post
    I agree with you Daniil, but i think that he meant select instead of load. Is that correct @FpNetWorth?
    Thank you @RCN.
    Yes, this is what I meant.
    Thank you for the clarification.
  6. #6
    Hi Daniil,

    Thank you for the sample that you provided.

    The problem that I face is that I can't get the value of the selected Item.

    When we click the button "Get", we have the following scenarios:
    1- If the user click "Get" without selecting any value from the combo, we get the selected text instead of the value.
    2- If the user select the same item that was selected on the load, we get the selected text instead of the value.
    3- If the user select a different item than the selected item on load, we get the true value of the selected item.

    Please find below the code:
    <%@ Page Language="C#" %>
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
     
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                Store store = this.ComboBox1.GetStore();
                store.DataSource = new object[] 
                { 
                    new object[] { 1, "Item 1" },
                    new object[] { 2, "Item 2" },
                    new object[] { 3, "Item 3" }
                };
                store.DataBind();
                this.ComboBox1.Value = 2;
            }
        }
     
        protected void Select(object sender, DirectEventArgs e)
        {
            this.ComboBox1.Value = 1;
        }
        protected void GetValue(object sender, DirectEventArgs e)
        {
            object comboValue = this.ComboBox1.Value;
            string comboVal = this.ComboBox1.SelectedItem.Value;
            object a = ComboBox1.SelectedItems[0].Value;
            
        }
        
    </script>
     
    <!DOCTYPE html>
     
    <html>
    <head id="Head1" runat="server">
        <title>Ext.NET v2 Example</title>
    </head>
    <body>
        <form id="Form1" runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" />
            <ext:ComboBox
                ID="ComboBox1"
                runat="server"
                DisplayField="text"
                ValueField="value">
                <Store>
                    <ext:Store ID="Store1" runat="server">
                        <Model>
                            <ext:Model ID="Model1" runat="server">
                                <Fields>
                                    <ext:ModelField Name="value" Type="Int" />
                                    <ext:ModelField Name="text" />
                                </Fields>
                            </ext:Model>
                        </Model>
                        <Reader>
                            <ext:ArrayReader />
                        </Reader>
                    </ext:Store>
                </Store>
            </ext:ComboBox>
            <ext:Button ID="Button1" runat="server" Text="Select" OnDirectClick="Select" />
            <ext:Button ID="Button2" runat="server" Text="Get" OnDirectClick="GetValue" />
        </form>
    </body>
    </html>
    Regards.
  7. #7
    It looks to be a bug. We are investigating.

    Thank you.
  8. #8
    It has been fixed in SVN.

    Thank you for the report.
  9. #9
    Quote Originally Posted by Daniil View Post
    It looks to be a bug. We are investigating.

    Thank you.

    Thank you Daniil..

Similar Threads

  1. Load combobox when opening
    By Birgit in forum 1.x Help
    Replies: 12
    Last Post: Apr 07, 2011, 11:27 AM
  2. [CLOSED] [1.0] ComboBox invalid on load
    By Timothy in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Sep 14, 2010, 10:45 PM
  3. Combobox isn't load correctly
    By flaviodamaia in forum 1.x Help
    Replies: 0
    Last Post: Mar 29, 2010, 9:19 AM
  4. Load ComboBox
    By usantos in forum 1.x Help
    Replies: 0
    Last Post: Mar 13, 2010, 12:29 PM
  5. combobox not load data
    By maxdiable in forum 1.x Help
    Replies: 2
    Last Post: Feb 05, 2010, 12:48 PM

Posting Permissions