PDA

View Full Version : [CLOSED] Problem with Combobox.SelectedItem



dataworks
May 22, 2015, 4:47 PM
We are having a recurring issue with setting combobox values in our projects. Every now and then we will get different behaviour from setting the selected item by using ComboBox.SelectedItem.Value. Sometimes ComboBox.SelectedItem.Value = "100" works, sometimes it doesn't. Sometimes ComboBox.SetValue("100") works, sometimes it doesn't. Test case below.




<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="com.bspr.crbspr.pages.WebForm1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<ext:ResourceManager ID="rsmMain" runat="server" Theme="Gray">
</ext:ResourceManager>

<ext:Viewport ID="vwpMain" runat="server">
<Items>

<ext:ComboBox runat="server" ID="cmbCDDTabID" FieldLabel="CDD Tab ID" ValueField="CDD_TAB_ID" DisplayField="CDD_TAB_DESC" AnchorHorizontal="99%" AllowBlank="false">
<Store>
<ext:Store ID="Store1" runat="server" IgnoreExtraFields="false">
<Model>
<ext:Model ID="Model1" runat="Server">
<Fields>
<ext:ModelField Name="CDD_TAB_ID" />
<ext:ModelField Name="CDD_TAB_DESC" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
</ext:ComboBox>

<ext:Button runat="server" ID="txtTest" Text="TEST">
<Listeners>
<Click Handler="App.direct.test();"></Click>
</Listeners>
</ext:Button>

</Items>
</ext:Viewport>

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




using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;

namespace com.bspr.crbspr.pages
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
cmbCDDTabID.Store[0].DataSource = new object[]
{
new object[] { "0", "none" },
new object[] { "100", "item1" },
new object[] { "200", "item2" },
new object[] { "300", "item3" }
};
cmbCDDTabID.Store[0].DataBind();
cmbCDDTabID.SelectedItem.Index = 0;
}

[DirectMethod]
public void test()
{
cmbCDDTabID.SelectedItem.Value = "100";
}
}
}

Vladimir
May 25, 2015, 12:04 PM
Hi

During DirectEvent/DirectMethod you have to use `SetValue` method


cmbCDDTabID.SetValue("100");


or call `UpdateSelectedItems` method after changing of SelectedItem(s)


cmbCDDTabID.SelectedItem.Value = "100";
cmbCDDTabID.UpdateSelectedItems();