[CLOSED] Problem Setting a ComboBox Value

  1. #1

    [CLOSED] Problem Setting a ComboBox Value


    My problem is that I cant set a default ComboBox value without a page load.

    Here is an example with a delailed explanation below.

    <%@ Page Title="Extranet Jhayber" Language="C#" 
        CodeBehind="Pruebaextnet.aspx.cs" Inherits="Extranet.Pruebaextnet" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <%@ Import Namespace="System.Collections.Generic" %>
    <%@ Import Namespace="System.Xml" %>
    <form runat="server">
        <ext:ResourceManager runat="server" />
        <ext:Viewport ID="Viewport1" runat="server" Layout="columnlayout" AutoScroll="true" >
                    <ext:Panel runat="server" id="panel1" ColumnWidth="1" Height="800" Frame="true">
                                FieldLabel="Select a single state"
                                    <ext:Store runat="server" id="Storecombo" AutoDataBind="true">
                                            <ext:Model runat="server">
                                                    <ext:ModelField Name="abbr" />
                                                    <ext:ModelField Name="name" />
                                                    <ext:ModelField Name="slogan" />
                                            <ext:ArrayReader />
                            <ext:Button runat="server" ID="button" Text="Combo default">
                                    <Click OnEvent="changecombo"></Click>
    namespace Extranet
        public partial class Pruebaextnet : System.Web.UI.Page
            protected void Page_Load(object sender, EventArgs e)
                Storecombo.DataSource = TestData;
                string defaultvalue = (string)(Session["default"]);
                    this.ComboExample.SelectedItems.Add(new Ext.Net.ListItem() { Value = defaultvalue });
            protected void changecombo(object sender, EventArgs e)
                this.ComboExample.SelectedItems.Add(new Ext.Net.ListItem() { Value = "AL" });
                Session["default"] = "AL";
            private object TestData
                    return new object[]
                    new object[] { "AL", "Alabama", "The Heart of Dixie" },
                    new object[] { "AK", "Alaska", "The Land of the Midnight Sun" },
                    new object[] { "AZ", "Arizona", "The Grand Canyon State" },
                    new object[] { "AR", "Arkansas", "The Natural State" },
                    new object[] { "CA", "California", "The Golden State" },
    What I want to do is to set the default value "AL" when I press the button, but this is not working. However, as you can see in the example, If I create a session with the default value "AL" and I do the same in the pageload, if i reload the page, It works nice.

    I want to do this, without reloading the page and use a session variable.

    Thank you for your time.
  2. #2
    Hello @PascuV!

    So your problem is not really setting the default selection but, once you change what should be the default selection, also set the combo box to the value you set as default?

    If so, I believe you are just missing a ComboExample.UpdateSelectedItems(); after you update the selection. It works during page load without this because the combo box is being built and a call to update the selection will be made during page/components rendering. Once it is already loaded you got to inform that the selection change you made you want to be made effective that moment, and extra client-side code is called to update the value just set.

    I hope this helps!
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. Replies: 10
    Last Post: May 16, 2014, 5:39 AM
  2. [CLOSED] Setting SelectedItems of a combobox from MVC Model
    By hikalkan in forum 2.x Premium Help
    Replies: 1
    Last Post: Apr 19, 2013, 11:50 AM
  3. Replies: 2
    Last Post: Aug 26, 2011, 3:22 PM
  4. [CLOSED] Setting a ComboBox Value
    By sisa in forum 1.x Premium Help
    Replies: 11
    Last Post: May 25, 2011, 10:45 AM
  5. [CLOSED] Setting Combobox value in code behind
    By iansriley in forum 1.x Premium Help
    Replies: 9
    Last Post: Dec 15, 2010, 8:35 PM

Posting Permissions