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

  1. #1

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

            <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>
    Last edited by Daniil; Oct 15, 2013 at 12:36 PM. Reason: [CLOSED]
  2. #2
    Hi @michaeld,

    Please use:
    <SelectedItems>
        <ext:ListItem Value="60" />
    </SelectedItems>
    instead of
    Value="60"
  3. #3
    Quote Originally Posted by Daniil View Post
    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.
  4. #4
    Quote Originally Posted by michaeld View Post
    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>

    Quote Originally Posted by michaeld View Post
    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>
    Quote Originally Posted by michaeld View Post
    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.
  5. #5
    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


    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.
  6. #6
    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.
  7. #7
    Like button. Damn, not facebook.
  8. #8
    Agreed, it would be nice to have. As on the Sencha forums.

Similar Threads

  1. Replies: 4
    Last Post: Oct 27, 2012, 11:59 AM
  2. Replies: 1
    Last Post: Sep 13, 2011, 6:19 PM
  3. Replies: 4
    Last Post: Feb 01, 2011, 12:54 PM
  4. [CLOSED] How to get the object from string
    By juane66 in forum 1.x Premium Help
    Replies: 2
    Last Post: Sep 22, 2010, 9:18 PM
  5. Replies: 0
    Last Post: Apr 14, 2009, 1:33 PM

Posting Permissions