PDA

View Full Version : [CLOSED] V2.0 ComboBox SelectedItem



Aurelio
Apr 01, 2012, 11:34 PM
Hi, it's possible select the first item ina combobox in c#?

I don't know the value of the items and need to select the first item (index = 0) in the combo.

ComboBox.SelectedItem.Value not work why the SelectedItem is null,
SelectedIndex not exist...

I do not know how to do

Thanks
Aurelio

Daniil
Apr 02, 2012, 11:51 AM
Hi,

This way:

Example

<ext:ComboBox runat="server">
...
<SelectedItems>
<ext:ListItem Index="0" />
</SelectedItems>
</ext:ComboBox>

Aurelio
Apr 02, 2012, 12:01 PM
HI, Daniil thanks, here it client side, but server side ?

I can not do it server-side..
I tested something similar, but I can not..


ComboBoxNazioni.SelectedItems.Add(new ListItem("","",0));
but this obviously puts a new item


Thanks
Aurelio

Daniil
Apr 02, 2012, 12:15 PM
Please use:

ComboBox1.SelectedItems.Add(new Ext.Net.ListItem { Index = 0 });

Aurelio
Apr 02, 2012, 1:36 PM
Hi, Daniil

many thanks it works ok..

If someone has the same problem, remember to add the line below the command to update the combo, otherwise the item will not be displayed



ComboBoxNazioni.SelectedItems.Add(new ListItem { Index = 0 });
ComboBoxNazioni.UpdateSelectedItems();


Thanks
Aurelio

Daniil
Apr 02, 2012, 2:28 PM
Yes, calling the UpdateSelectedItems is required the change to be affected during DirectEvent/DirectMethod.