We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Set selected item by value

Hi !

I´m using "WebSamplerBrowser"provided by you to learn some components features.
In COMBOBOX "Databiding-local" example, I´ve added a button to select an item by clicking on it as shown bellow:

ASPX
<asp:Content ID="Content1" ContentPlaceHolderID="ControlsSection" runat="server">
    <div class="frame">
        <div class="control">
            <ej:ComboBox ID="selectState" runat="server" Width="100%" DataTextField="countryName" DataValueField="index" Placeholder="Select a state">
            </ej:ComboBox>
            <br />
            <ej:Button ID="Button1" runat="server" Type="Button" Text="Click me to select North Carolina" Size="Mini" OnClick="selectMyItem" />
        </div>
    </div>
</asp:Content> 

Code-behind
 protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                this.selectState.DataSource = States.GetStates();
            }
            
        }

        protected void selectMyItem(object Sender, Syncfusion.JavaScript.Web.ButtonEventArgs e)
        {
            this.selectState.Value = "s26";
        }

The event is fired as expected but the item is not selected.

What´s wrong here ?

Thank´s !

3 Replies

PO Prince Oliver Syncfusion Team November 23, 2018 04:35 PM UTC

Hi Fabio, 

Thank you for contacting Syncfusion support. 

We have checked the reported issue in our end. This issue occurs because dataSource is not maintained after postback. We suggest you to set DataSourceCachingMode="Session" for ComboBox to resolve this issue. Please refer to the below given code 
 
<ej:ComboBox ID="selectState" runat="server" Width="300px" DataTextField="countryName"  DataValueField="index" Placeholder="Select a state" DataSourceCachingMode="Session"> 
            </ej:ComboBox> 

Please let us know if you require any further assistance on this. 

Regards, 
Prince 



FM Fabio Marcos Euzebio November 23, 2018 07:36 PM UTC

Works perfectly !

Thanks


PO Prince Oliver Syncfusion Team November 26, 2018 05:40 AM UTC

Hi Fabio, 

Most Welcome. We are glad to help you. 

Regards, 
Prince 


Loader.
Live Chat Icon For mobile
Up arrow icon