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

Problem with SelectedIndexChanged

3 Answers 113 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Paolo
Top achievements
Rank 1
Paolo asked on 18 Mar 2009, 09:33 PM
Hello,

I'm having quite an annoying problem with Radcombobox.
Here's the scenario, very simple:

ASPX
               <telerik:RadComboBox ID="RadComboBox1" runat="server" Width="300px" Skin="Web20"  
               EmptyMessage="Choose layout..." AutoPostBack="true" HighlightTemplatedItems="True" 
               OnSelectedIndexChanged="RadComboBox1_SelectedIndexChanged"  
               AllowCustomText="true" > 
                  <ItemTemplate> 
                      <img src='<%# DataBinder.Eval(Container, "Attributes['ImagePath']") %>'  alt=""/> 
                  </ItemTemplate> 
                   <Items> 
                       <telerik:RadComboBoxItem ImagePath="../Grafica/Layout1.png" Value="Layout1"></telerik:RadComboBoxItem> 
                       <telerik:RadComboBoxItem ImagePath="../Grafica/Layout2.png" Value="Layout2"></telerik:RadComboBoxItem> 
                       <telerik:RadComboBoxItem ImagePath="../Grafica/Layout3.png" Value="Layout3"></telerik:RadComboBoxItem> 
                       <telerik:RadComboBoxItem ImagePath="../Grafica/Layout4.png" Value="Layout4"></telerik:RadComboBoxItem> 
                       <telerik:RadComboBoxItem ImagePath="../Grafica/Layout5.png" Value="Layout5"></telerik:RadComboBoxItem> 
                       <telerik:RadComboBoxItem ImagePath="../Grafica/Layout6.png" Value="Layout6"></telerik:RadComboBoxItem> 
                   </Items> 
               </telerik:RadComboBox> 
 

Code Behind
    protected void Page_Load(object sender, EventArgs e) 
    { 
        if (!Page.IsPostBack) 
        { 
            for (int i = 0; i < RadComboBox1.Items.Count; i++) 
            { 
                RadComboBox1.Items[i].DataBind(); 
            } 
        } 
    } 
    protected void RadComboBox1_SelectedIndexChanged(object o, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e) 
    { 
        string strSelectedValue = RadComboBox1.SelectedValue; 
        // other stuff 
 

I've already tried everything but I can't still get the SelectedIndexChanges event to fire when I select the first item.
Of course the problem is that the SelectedIndex at the begin is set to 0, that's the first item, but how can I change this behaviour.
Or still better, how can I get the above example to work..?

Thank you

Regards,

Paolo





3 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 19 Mar 2009, 03:39 PM
Hi Paolo,

Please set the Text property of the items as well.

... 
<Items>  
                       <telerik:RadComboBoxItem ImagePath="../Grafica/Layout1.png" Value="Layout1" Text="Layout1"></telerik:RadComboBoxItem>  
                       <telerik:RadComboBoxItem ImagePath="../Grafica/Layout2.png" Value="Layout2" Text="Layout2"></telerik:RadComboBoxItem>  
                       <telerik:RadComboBoxItem ImagePath="../Grafica/Layout3.png" Value="Layout3" Text="Layout3"></telerik:RadComboBoxItem>  
... 


Best wishes,
Veselin Vasilev
the Telerik team


Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Paolo
Top achievements
Rank 1
answered on 19 Mar 2009, 06:08 PM
Hi Veselin,

thank you for your answer.

I tried your tip but unfortunately it doesn't seem to do the trick, or at least not completely.
In fact, the first time I run the page if I chose the first item the SelectedIndexChanged is not being fired. Chosing another item, the second one for example, the event is fired. After the postback the event fires even if I chose the first item but as soon as the postback returns here's again the first item doesn't fire the the event.
I thinking to drop this problem placing a sort of submit button. Certainly, from usability point of view, is all but a good solution.
Do you have any other suggestions?

Regards,

Paolo


0
Atanas Korchev
Telerik team
answered on 20 Mar 2009, 12:03 PM
Hi Paolo,

By default the SelectedIndexChanged event is not fired for the item already selected as in fact the selected index never changes. This behavior can be observed with the DropDownList control. Why do you need the SelectedIndexChanged event to fire always? This is quite the contrary to what most developers would expect.

Regards,
Albert
the Telerik team


Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
ComboBox
Asked by
Paolo
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Paolo
Top achievements
Rank 1
Atanas Korchev
Telerik team
Share this question
or