-1

In my master page ,I have a AspxComboBox in side ASPxMenu item's Template tag I am able to access it on any aspx page but when I am trying set its Value Or SelectedIndex then changes not updating

<dx:MenuItem>
          <Template>
             <dx:ASPxComboBox ID="CbalarmSelect" runat="server" AutoPostBack="true" ViewStateMode="Enabled"  OnSelectedIndexChanged="cbalarmselect_changed">
           <Items>
              <dx:ListEditItem Text="Select Option" Selected="true" Value="0" />
              <dx:ListEditItem  Text="Sample" Value="1" />
              <dx:ListEditItem Text="Demo" Value="2" />
           </Items>
   </dx:ASPxComboBox>
  </Template>
 </dx:MenuItem>

C# code to access this ComboBox

 ASPxMenu item = (ASPxMenu)Master.FindControl("ASPxMenu1");  
 ASPxComboBox combo = (ASPxComboBox)item.Items.FindByName("AlarmSubscription").FindControl("CbalarmSelect");
 combo.SelectedIndex =1  ;

for test purpose I set its visibility false combo.Visible = false; but it is visible mean set functionality not working

Umang Patwa
  • 2,795
  • 3
  • 32
  • 41
  • 1
    The key to solve your problem is understanding how page life cycle works. The Page code always runs before Master page code, thus any changes in Page code behind will overwritten by Master code behind if exists. If you have Master code behind, show it in your question (including methods related to Master's `ASPxComboBox`). – Tetsuya Yamamoto Dec 13 '16 at 09:22
  • No code in master page related to this `ASPxComboBox` only on its change event I am using this to check its selected Index @TetsuyaYamamoto – Umang Patwa Dec 13 '16 at 11:18

2 Answers2

0

I was trying to set SelectedIndex during Page_Load event and it not working.then I move my code in Page_LoadComplete event and it worked for me

void Page_LoadComplete(object sender, EventArgs e)
{
                ASPxMenu item = (ASPxMenu)Master.FindControl("ASPxMenu1");  
                ASPxComboBox combo =         (ASPxComboBox)item.Items.FindByName("AlarmSubscription").FindControl("CbalarmSelect");
                combo.SelectedIndex =1  ;
}
Umang Patwa
  • 2,795
  • 3
  • 32
  • 41
-1

Client-Side Script

Give ClientInstanceName property to comboBoxto access it client side and ID property as cbxJobType to access control server side.

// by text
comboBox.SetText('Text #2');
// by value
comboBox.SetValue('Value #2');
// by index
comboBox.SetSelectedIndex(1);

Server-Side Code

// by text
cbalarmSelect.Text = "Text #2";
// by value
cbalarmSelect.Value = "Value #2";
// by index
cbalarmSelect.SelectedIndex = 1; 

This code works fine too:

cbalarmSelect.SelectedItem = cbalarmSelect.Items.FindByValue("Value #2");

ASPxComboBox , How to set selected item?

Community
  • 1
  • 1
  • I want to set it by C# because i have another combo box where c# is must like language combo box if I select English then how will I permanently set it on all page ? – Umang Patwa Dec 12 '16 at 09:19