Oct 30, 2015, 1:40 PM
[CLOSED] GetStore() on ComboBox with static ListItems wipes out the ListItem collection
GetStore() on ComboBox with static ListItems wipes out the ListItem collection. Try to remove this line:
What's happening here?
Thank you!
-r-
Ext.Net.Store myStore = MyCombo.GetStore();
... and the sample will work with no exception.What's happening here?
Thank you!
-r-
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
// this line will wipe out the ListItem collection
Ext.Net.Store myStore = MyCombo.GetStore();
//
string value = MyCombo.SelectedItem.Value;
if (string.IsNullOrEmpty(value))
{
Store store = MyCombo.GetStore();
if (store != null)
{
DataTable dt = null;
if (store.DataSource is DataTable)
{
dt = store.DataSource as DataTable;
}
if (store.DataSource is DataSet)
{
DataSet ds = store.DataSource as DataSet;
if (ds.Tables.Count > 0)
{
dt = ds.Tables[0];
}
}
if (dt != null && dt.Rows.Count > 0)
{
value = Convert.ToString(dt.Rows[0][MyCombo.ValueField]);
}
else
{
value = MyCombo.Items[0].Value;
}
}
}
// do something with value
}
</script>
<!DOCTYPE html>
<html>
<head id="Head1" runat="server">
</head>
<body>
<form id="Form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" />
<ext:ComboBox
InputWidth="350"
ID="MyCombo"
runat="server"
FieldLabel="MyCombo"
PreselectFirstItem="True"
EmptyText=""
Editable="false"
QueryMode="Local"
TriggerAction="All"
AllowBlank="false">
<Items>
<ext:ListItem Text="AAA" Value="1" />
<ext:ListItem Text="BBB" Value="2" />
<ext:ListItem Text="CCC" Value="3" />
</Items>
</ext:ComboBox>
</form>
</body>
</html>
Last edited by Daniil; Oct 31, 2015 at 8:34 AM.
Reason: [CLOSED]