This is a migrated thread and some comments may be shown as answers.

[Solved] Text and Value of all items empty

2 Answers 110 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Jeroen Eikmans
Top achievements
Rank 1
Jeroen Eikmans asked on 04 Jun 2009, 08:17 AM

Hello,

I have a Combobox where i add the items programmatically. In the OnSelectedIndexChanged event i want to save the new selected value. I tried this with the evaluation controls and this worked. Now i've bought the Q1 2009 Developer license, installed them and my code isn't working anymore.

Below is the code of a small testproject i made, reproducing the problem. On PostBack in the Init event the ComboBox.Items is first empty. In SelectedIndexChanged the Combobox.Items is filled again with the number of items i added but both Value and Item properties are empty.

Is there some property i need to set now or use some other events?

<telerik:RadScriptManager ID="RadScriptManager1" runat="server">  </telerik:RadScriptManager> 
  <telerik:RadComboBox ID="RadComboBox1" Runat="server"   
    oninit="RadComboBox1_Init"   
    onselectedindexchanged="RadComboBox1_SelectedIndexChanged"   
    AutoPostBack="True" > 
  </telerik:RadComboBox> 
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> 
 

protected void RadComboBox1_Init(object sender, EventArgs e)  
{  
    RadComboBox1.Enabled = true;  
    if (!Page.IsPostBack)  
    {  
        RadComboBox1.Items.Clear();  
        RadComboBox1.Items.Add(new RadComboBoxItem("Item 1""1"));  
        RadComboBox1.Items.Add(new RadComboBoxItem("Item 2""2"));  
        RadComboBox1.Items.Add(new RadComboBoxItem("Item 3""3"));  
        RadComboBox1.Items.Add(new RadComboBoxItem("Item 4""4"));  
        RadComboBox1.Items.Add(new RadComboBoxItem("Item 5""5"));  
    }  
}  
 
protected void RadComboBox1_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)  
{  
    Label1.Text = RadComboBox1.SelectedItem.Text + " : " + RadComboBox1.SelectedItem.Value;  

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 04 Jun 2009, 09:21 AM
Hi Roel Martens,

Can you try adding combo items in Load event instead of Init event and see whether it is working fine?

CS:
 
protected void RadComboBox1_Load(object sender, EventArgs e) 
    if (!Page.IsPostBack) 
    { 
        RadComboBox1.Items.Clear(); 
        RadComboBox1.Items.Add(new RadComboBoxItem("Item 1""1")); 
        RadComboBox1.Items.Add(new RadComboBoxItem("Item 2""2")); 
        RadComboBox1.Items.Add(new RadComboBoxItem("Item 3""3")); 
        RadComboBox1.Items.Add(new RadComboBoxItem("Item 4""4")); 
        RadComboBox1.Items.Add(new RadComboBoxItem("Item 5""5")); 
    }   
I guess the items are not preserved because the view-state information is not used in Init event.

-Shinu.
0
Jeroen Eikmans
Top achievements
Rank 1
answered on 04 Jun 2009, 09:58 AM
Hi Shinu,

Thanks for the fast reply.
It is indeed working now again when i use the Load event instead of the Init event.
Tags
ComboBox
Asked by
Jeroen Eikmans
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Jeroen Eikmans
Top achievements
Rank 1
Share this question
or