views:

65

answers:

1

I have two combo and one button. child combo fill on basis of parent combo key value. click on parent combo value will change on child combo,click on button show those combo selected text.I can do it bellow in my syntax.i use north wind database.

<div>
            <dx:ASPxComboBox ID="ASPxComboBoxParent" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ASPxComboBoxParent_SelectedIndexChanged"
                TextField="ShipName" ValueField="OrderID" ValueType="System.Int32">
            </dx:ASPxComboBox>
            <dx:ASPxComboBox ID="ASPxComboBoxChild" runat="server" TextField="ProductID" ValueField="OrderID"
                ValueType="System.Int32">
            </dx:ASPxComboBox>
            <dx:ASPxButton ID="ASPxButton1" runat="server" OnClick="ASPxButton1_Click" Text="ASPxButton">
            </dx:ASPxButton>
            <dx:ASPxLabel ID="ASPxLabelMessage" runat="server">
            </dx:ASPxLabel>
        </div>

C# syntax

protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                NorthwindDataContext db=new NorthwindDataContext();
                var r=from p in db.Orders
                      select p;
                ASPxComboBoxParent.DataSource = r;
                ASPxComboBoxParent.DataBind();
            }

        }

        protected void ASPxComboBoxParent_SelectedIndexChanged(object sender, EventArgs e)
        {
            NorthwindDataContext db=new NorthwindDataContext();
            int a= Convert.ToInt32( ASPxComboBoxParent.SelectedItem.Value);
            var r = from p in db.Order_Details
                    where p.OrderID == a
                    select p;

            ASPxComboBoxChild.DataSource = r;
            ASPxComboBoxChild.DataBind();
            ASPxComboBoxChild.SelectedIndex = 1;
        }

        protected void ASPxButton1_Click(object sender, EventArgs e)
        {


            ASPxLabelMessage.Text = "Parent is" + Convert.ToString(ASPxComboBoxParent.SelectedItem.Text) + "And child is" + Convert.ToString(ASPxComboBoxChild.SelectedItem.Text);
        }

After click the parent combo,child combo fill But click on button always get child combo index=0 value event i change the child combo value .Why not value change on button event? if have any query plz ask me.thanks in advance.

A: 

Hi,

The problem appears because the ASPxComboBoxChild.ValueField property points to a value containing the same values. I.e. when the ASPxComboBoxParent selected index is changed, the ASPxComboBoxChild's Items collection is filled with items whose Value property is the same. Since the ASPxComboBox distinguishes between items by their Value, the problem appears. The solution is easy:

<dx:ASPxComboBox ID="ASPxComboBoxChild" runat="server" TextField="ProductID" ValueField="ProductID"
                ValueType="System.Int32">
            </dx:ASPxComboBox>
DevExpress Team