[CLOSED] Assigning ComboBox Value

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    [CLOSED] Assigning ComboBox Value

    Hi
    ComboBox1.Value = "some value" works fine when values are hard-coded. When derived from a DataSource assigning the value appears to fail. Please see the following basic Northwind sample.

    protected void Page_Load(object sender, EventArgs e)
    {
            if (!X.IsAjaxRequest)
            {
                ComboBox1.Value = "5";
            }
    }
    <asp:SqlDataSource 
        ID="SqlDataSource1" 
        runat="server" 
        ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
        SelectCommand="
        SELECT 
            [EmployeeID], 
            [LastName]
        FROM [Employees]"
        />
    
    
    <ext:Store ID="Store1" runat="server" DataSourceID="SqlDataSource1">
        <Model>
            <ext:Model ID="Model1" runat="server" IDProperty="EmployeeID">
                <Fields>
                    <ext:ModelField Name="EmployeeID" />
                    <ext:ModelField Name="LastName" />
                </Fields>
            </ext:Model>
        </Model>
    </ext:Store>
    
    
    <ext:ComboBox 
        ID="ComboBox1" 
        runat="server" 
        StoreID="Store1" 
        DisplayField="LastName"
        ValueField="EmployeeID">
    </ext:ComboBox>
    Last edited by Daniil; Mar 11, 2012 at 4:44 PM. Reason: [CLOSED]
  2. #2
    Hi,

    You should apply an integer value, not a string one.
    ComboBox1.Value = 5;
    because EmployeeID has integer type.
  3. #3
    Haha - that's what you get when looking at code when you're too tired. Thanks Daniil (you can close),
    A.
  4. #4
    Actually there is a problem here ... using the example below if you click the button without making a selection from the combobox you will get an incorrect value (retrieving 'text' rather than 'value'). If you make a selection on the combobox and then click the button it works fine.

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!X.IsAjaxRequest)
        {
            ComboBox1.Value = 6;
        }
    }
    
    protected void Button_Click(object sender, DirectEventArgs e)
    {
        X.Msg.Alert("ComboBox1 Value", "Combo Value: " + ComboBox1.SelectedItem.Value).Show();
    }

    <asp:SqlDataSource 
        ID="SqlDataSource1" 
        runat="server" 
        ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
        SelectCommand="
        SELECT 
            [EmployeeID], 
            [LastName]
        FROM [Employees]"
        />
    
    
    <ext:Store ID="Store1" runat="server" DataSourceID="SqlDataSource1">
        <Model>
            <ext:Model ID="Model1" runat="server">
                <Fields>
                    <ext:ModelField Name="EmployeeID" />
                    <ext:ModelField Name="LastName" />
                </Fields>
            </ext:Model>
        </Model>
    </ext:Store>
    
    
    <ext:ComboBox 
        ID="ComboBox1" 
        runat="server" 
        StoreID="Store1" 
        DisplayField="LastName"
        ValueField="EmployeeID">
    </ext:ComboBox>
    
    
    <ext:Button ID="Button1" runat="server" Text="Click Me">
        <DirectEvents>
            <Click OnEvent="Button_Click" />
        </DirectEvents>
    </ext:Button>
  5. #5
    Confirmed.

    Please populate the ComboBox SelectedItems collection instead of setting up its Value.

    Example
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!X.IsAjaxRequest)
        {
            ComboBox1.SelectedItems.Add(new Ext.Net.ListItem()
            {
                CustomConfig =
                {
                    new ConfigItem("value", "6", ParameterMode.Raw)
                }
            });
        }
    }

Similar Threads

  1. [CLOSED] Assigning and adding data in Text Field
    By Digital.Dynamics in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: May 24, 2012, 9:33 AM
  2. Replies: 4
    Last Post: Nov 30, 2011, 6:25 AM
  3. [CLOSED] Assigning store data from javascript not working
    By SymSure in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: May 05, 2011, 3:07 PM
  4. Replies: 11
    Last Post: Dec 14, 2010, 7:42 AM
  5. [CLOSED] Assigning multiple custom targets
    By LeeTheGreek in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jun 07, 2010, 9:16 AM

Posting Permissions