PDA

View Full Version : [CLOSED] ComboBox Value causes Cannot create an object of type 'System.Object' from its string representation '60''



michaeld
Oct 10, 2013, 8:14 AM
<ext:ComboBox ID="Miles" runat="server" Flex="1" Visible="false" Width="80" PaddingSpec="0 3px" Value="60"
Editable="true" ForceSelection="true" QueryMode="Local">
<Items>
<ext:ListItem Text="8 miles" Value="8" />
<ext:ListItem Text="15 miles" Value="15" />
<ext:ListItem Text="30 miles" Value="30" />
<ext:ListItem Text="60 miles" Value="60" />
<ext:ListItem Text="90 miles" Value="90" />
<ext:ListItem Text="120 miles" Value="120" />
<ext:ListItem Text="180 miles" Value="180" />
</Items>
<Listeners>
<KeyUp Handler="Zipset.redir();" />
</Listeners>
</ext:ComboBox>

Daniil
Oct 10, 2013, 8:54 AM
Hi @michaeld,

Please use:

<SelectedItems>
<ext:ListItem Value="60" />
</SelectedItems>
instead of

Value="60"

michaeld
Oct 10, 2013, 9:45 AM
Please use:

<SelectedItems>
<ext:ListItem Value="60" />
</SelectedItems>
instead of

Value="60"

I noted elsewhere that option triggers select. All I can do is note the trouble with setting Value since it caused an obvious exception which I thought you might want to rectify if dev solution exists. I understand the other options and workarounds as well. The simplest option to prevent select firing is to set Text which has its own inherent problems combined with different attributes and usage.

I'm working some of these out now. I may have to extend some of the classes if/when I turn over my code to other developers so they don't run down some of the same paths I have.

I also seem to remember a thread on discussing supporting Value.

Daniil
Oct 10, 2013, 2:32 PM
I noted elsewhere that option triggers select.

SelectedItems should not fire the Select event. I cannot reproduce. I tried with ComboBoxes with Items and a Store with Proxy.

Example

<%@ Page Language="C#" %>

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

<script runat="server">
protected void Store_ReadData(object sender, EventArgs e)
{
Store store = sender as Store;
store.DataSource = new object[]
{
new object[] { "1", "Item 1" },
new object[] { "2", "Item 2" },
new object[] { "3", "Item 3" }
};
System.Threading.Thread.Sleep(3000);
}
</script>

<!DOCTYPE html>

<html>
<head runat="server">
<title>Ext.NET v2 Example</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />

<ext:ComboBox runat="server">
<Items>
<ext:ListItem Text="Item 1" Value="1" />
<ext:ListItem Text="Item 2" Value="2" />
</Items>
<SelectedItems>
<ext:ListItem Value="1" />
</SelectedItems>
<Listeners>
<Select Handler="console.log('Select');" />
</Listeners>
</ext:ComboBox>

<ext:ComboBox runat="server" DisplayField="text" ValueField="value">
<Store>
<ext:Store runat="server" OnReadData="Store_ReadData">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="value" />
<ext:ModelField Name="text" />
</Fields>
</ext:Model>
</Model>
<Proxy>
<ext:PageProxy>
<Reader>
<ext:ArrayReader />
</Reader>
</ext:PageProxy>
</Proxy>
</ext:Store>
</Store>
<SelectedItems>
<ext:ListItem Value="1" />
</SelectedItems>
<Listeners>
<Select Handler="console.log('Select');" />
</Listeners>
</ext:ComboBox>
</form>
</body>
</html>




All I can do is note the trouble with setting Value since it caused an obvious exception which I thought you might want to rectify if dev solution exists.

This exception is caused by the markup parser. A ComboBox's Value is "object" type. So, the parser somehow cannot create an object from a string representation. I was always curious why. However, I doubt we can get rid of that exception. Do you have a solution?

Anyway, if needed you could set up it in code behind or this way:

<ext:ComboBox runat="server" Value='<%# "1" %>' AutoDataBind="true">
<Items>
<ext:ListItem Text="Item 1" Value="1" />
<ext:ListItem Text="Item 2" Value="2" />
</Items>
<Listeners>
<Select Handler="console.log('Select');" />
</Listeners>
</ext:ComboBox>


I also seem to remember a thread on discussing supporting Value.

Seems it was a bit different discussion. As for the current problem, the Value is actually supported.

michaeld
Oct 11, 2013, 1:14 AM
Sorry, you are right. It's not the select event that's fired, but the change event. I really need to focus when it's very late night for me. I've switched my work hours to late nights so I can match more closely to yours until we go to launch.

See here where I reveal this situation...
http://forums.ext.net/showthread.php?26765-SelectBox-in-2-0-does-not-behave-the-same-as-1-X-amp-other-ComboBox-ramblings (http://forums.ext.net/showthread.php?26765-SelectBox-in-2-0-does-not-behave-the-same-as-1-X-amp-other-ComboBox-ramblings)

You should be able to reproduce with your code if you change select to change.

I'll look into the value issue, but my first instinct is to override Value.

Daniil
Oct 15, 2013, 10:40 AM
Yes, the Change event fires for SelectedItems.

It makes sense to have an option to prevent it if needed. The FireChangeOnLoad option has been added to the trunk. It is true by default. Please set up to false to prevent the Change event for SelectedItems.

Please note that a ComboBox's Change event doesn't fire for an initial Value on page load.

michaeld
Oct 15, 2013, 12:04 PM
Like button. Damn, not facebook.

Daniil
Oct 15, 2013, 12:35 PM
Agreed, it would be nice to have. As on the Sencha forums.