Tuesday, 22 September 2015

Devexpress: datasource binded ASPxComboBox fail to set selected on page load

                <dx:ASPxComboBox  ValueField="Id" TextField="Ethinicity" DataSourceID="ethincitydatasource"  SelectedIndex="0" runat="server" ID="cmbEthinicity" Width="250px" Height="32px" CssClass="textbox-style-account" ValueType="System.Int32">
                                    <DropDownButton>
                                        <Image Url="images/down.png"></Image>
                                    </DropDownButton>
                                    <ValidationSettings ValidationGroup="SaveCompanyInfo" Display="Static" ErrorDisplayMode="Text" ErrorTextPosition="Bottom" EnableCustomValidation="True" CausesValidation="True">
                                        <RequiredField IsRequired="True" ErrorText="Select Ethinicity" />
                                    </ValidationSettings>
                                </dx:ASPxComboBox>
                                <data: EthinicityMasterDataSource runat="server" ID="ethincitydatasource" SelectMethod="GetAll"></data: EthinicityMasterDataSource>

Code on cs

protected void Page_Load(object sender, EventArgs e)
    {if (!IsPostBack)
            {
                     cmbEthinicity.DataBind();
                     cmbEthinicity.Value = Convert.ToInt32(objPpiClient.EthinicityId);
}
}

Key solution: cmbEthinicity.DataBind();

bind again before setting selected index.
                         



Avast logo
This email has been checked for viruses by Avast antivirus software.
www.avast.com

No comments:

Post a Comment