PDA

View Full Version : [CLOSED] [2.2] Combobox selecteditem problem



John_Writers
Oct 09, 2013, 9:33 AM
Hi,
with combobox I can't select the item by value.
The follow code explain the example:


<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack && !X.IsAjaxRequest)
{
for (int i = 0; i < 10; i++)
{
cb.Items.Add(new Ext.Net.ListItem()
{
Text = "Value of :" + i.ToString(),
Value = i.ToString()
});
}
}
}
protected void btn_Click(object sender, DirectEventArgs e)
{
Ext.Net.ListItem li = new Ext.Net.ListItem(2);
li.Mode = ParameterMode.Raw;

cb.SelectedItems.Add(li);
//cb.SelectedItem.Value = "2";
//cb.SetValue(2);
}

</script>
<form id="form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" Theme="Gray" CleanResourceUrl="false" RethrowAjaxExceptions="true">
</ext:ResourceManager>

<ext:ComboBox ID="cb" runat="server" Editable="false" Width="400" AllowBlank="false" >

</ext:ComboBox>
<ext:Button runat="server" Text="select">
<DirectEvents>
<Click OnEvent="btn_Click"></Click>

</DirectEvents>

</ext:Button>

</form>
</body>
</html>


I try to use tree method to select by value.
1. To add the listitem to SelectedItems collection - not works
2. Use SelectedItem.Value - not works
3. Use setValue method - This show the vallue and not select by value (The combo show 2 intead of "Value of : 2")

Can you help me?
thanks

Daniil
Oct 09, 2013, 12:15 PM
Hi John,

There are two issues.

1. If you deal with a SelectedItems collection during a DirectEvent, you should call:

cb.UpdateSelectedItems();
after modifications.

2. There must be matching in types. You bind strings as items' values, but want to select "2" of int type.

So, this is working.

protected void btn_Click(object sender, DirectEventArgs e)
{
Ext.Net.ListItem li = new Ext.Net.ListItem("2");
cb.SelectedItems.Add(li);
cb.UpdateSelectedItems();
}

John_Writers
Oct 09, 2013, 12:51 PM
Its works.

Thanks