[CLOSED] Load 1 item to combobox store and get value of selected item on serverside

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] Load 1 item to combobox store and get value of selected item on serverside

    Hi,

    I need to set value to combobox store:

    This is related question to this:
    http://forums.ext.net/showthread.php...tances-are-met


    configuration of store:
    http://forums.ext.net/showthread.php...ll=1#post98333

    what I have tryed:
    object o = Activator.CreateInstance(type,new object[]{1,null};//type is System.Type of my BLL Object
    combo.Store.AddRecord(o);//here I got exception JsonSerializationException do I need serialize this 'o' element? Store is simply Property which return store of combo(my custom server control inherited from CompositeField contains combobox and ext.net.button
    Thanks,
    ViDom
    Last edited by Daniil; Dec 17, 2012 at 11:26 AM. Reason: [CLOSED]
  2. #2
    Hi @ViDom,

    An object must be serializable. A Dictionary or just an anonymous object.

    Example
    Store store = this.ComboBox1.GetStore();
    
    store.AddRecord(new
    {
        value = "4",
        text = "Item 4"
    });
    or
  3. #3
    Quote Originally Posted by Daniil View Post
    Hi @ViDom,

    An object must be serializable. A Dictionary or just an anonymous object.

    Example
    Store store = this.ComboBox1.GetStore();
    
    store.AddRecord(new
    {
        value = "4",
        text = "Item 4"
    });
    or
    ok but after add this record It should be selected on begin and stay that way since user will reload store and change(or not next problem seems to occur here). When I do it like this
    ComboBox1.Value = 4;
    it's displaying 4 but should display 'Item 4' string. I have be able to display Item 4 by assigning it to Value property of combobox but not sure if it's good idea ( i need to get this value on button event)

    and how to prevent combobox event to ask ( uncommited changes ) on reload store if there is loaded item this way?

    please tell me if this can be done another way( way to know which item is selected if user doesn't change selection on serverside) or maybe this way described above is good?
    Last edited by ViDom; Dec 13, 2012 at 1:42 PM.
  4. #4
    Quote Originally Posted by ViDom View Post
    When I do it like this
    ComboBox1.Value = 4;
    it's displaying 4 but should display 'Item 4' string. I have be able to display Item 4 by assigning it to Value property of combobox but not sure if it's good idea ( i need to get this value on button event)
    I am unable to reproduce. Please provide a test case.

    Here is my one.

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                Store store = this.ComboBox1.GetStore();
                store.DataSource = new object[] 
                { 
                    new object[] { 1, "item1" },
                    new object[] { 2, "item2" },
                    new object[] { 3, "item3" }
                };
                store.DataBind();
            }
        }
    
        protected void Add(object sender, DirectEventArgs e)
        {
            Store store = this.ComboBox1.GetStore();
    
            store.AddRecord(new
            {
                value = 4,
                text = "Item 4"
            });
    
            this.ComboBox1.Value = 4;
        }
    </script>
    
    <!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>Ext.NET Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            <ext:ComboBox ID="ComboBox1" runat="server">
                <Store>
                    <ext:Store runat="server">
                        <Reader>
                            <ext:ArrayReader>
                                <Fields>
                                    <ext:RecordField Name="value" Type="Int" />
                                    <ext:RecordField Name="text" />
                                </Fields>
                            </ext:ArrayReader>
                        </Reader>
                    </ext:Store>
                </Store>
            </ext:ComboBox>
            <ext:Button runat="server" Text="Add" OnDirectClick="Add" />
        </form>
    </body>
    </html>

    Quote Originally Posted by ViDom View Post
    and how to prevent combobox event to ask ( uncommited changes ) on reload store if there is loaded item this way?
    Please set up WarningOnDirty="false" for the Store.

    Quote Originally Posted by ViDom View Post
    way to know which item is selected if user doesn't change selection on serverside
    A selected item's value should be accessible on a server via:
    this.ComboBox1.SelectedItem.Value
  5. #5
    Quote Originally Posted by Daniil View Post
    I am unable to reproduce. Please provide a test case.

    Here is my one.

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                Store store = this.ComboBox1.GetStore();
                store.DataSource = new object[] 
                { 
                    new object[] { 1, "item1" },
                    new object[] { 2, "item2" },
                    new object[] { 3, "item3" }
                };
                store.DataBind();
            }
        }
    
        protected void Add(object sender, DirectEventArgs e)
        {
            Store store = this.ComboBox1.GetStore();
    
            store.AddRecord(new
            {
                value = 4,
                text = "Item 4"
            });
    
            this.ComboBox1.Value = 4;
        }
    </script>
    
    <!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>Ext.NET Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            <ext:ComboBox ID="ComboBox1" runat="server">
                <Store>
                    <ext:Store runat="server">
                        <Reader>
                            <ext:ArrayReader>
                                <Fields>
                                    <ext:RecordField Name="value" Type="Int" />
                                    <ext:RecordField Name="text" />
                                </Fields>
                            </ext:ArrayReader>
                        </Reader>
                    </ext:Store>
                </Store>
            </ext:ComboBox>
            <ext:Button runat="server" Text="Add" OnDirectClick="Add" />
        </form>
    </body>
    </html>



    Please set up WarningOnDirty="false" for the Store.



    A selected item's value should be accessible on a server via:
    this.ComboBox1.SelectedItem.Value
    I confirm that value is accesible on server via
    this.ComboBox1.SelectedItem.Value
    here is my sample to reproduce loading one record on begin(I have edited post and add this issue):
    http://forums.ext.net/showthread.php...ll=1#post98429
    Last edited by ViDom; Dec 14, 2012 at 9:26 AM.
  6. #6
    This code:
    protected void Page_Load(object sender, EventArgs e)
    {
        mycontrol.Store.AddRecord(new { Id = 1, Name = "first" });//tryed also mycontrol.ComboBox.GetStore().AddRecord(new { Id=1, Name="first"}); it's make same result  display 1 when should display "first"
        mycontrol.ComboBox.Value = 1;
    }
    The AddRecord should not be used in a Page_Load handler. It is designed to be used during an Ext.NET AJAX request.

    What about to preload a required item?

    You can change it to true:
    store.AutoLoad = false;
    And set up a parameter in the AutoLoadParams collection which would mean "load the default value".

    Generally, you configure an HttpProxy for the Store. It means to load the data remotely. But trying to set up a default item in the Page_Load. IMHO, this is not very well.

    You could try this:
    mycontrol.ComboBox.Value = 1;
    mycontrol.ComboBox.Text = "Item 1";
    It should work as you need, but it is a tricky thing. For example, it doesn't work in Ext.NET v2.
  7. #7
    Quote Originally Posted by Daniil View Post
    You could try this:
    mycontrol.ComboBox.Value = 1;
    mycontrol.ComboBox.Text = "Item 1";
    It should work as you need, but it is a tricky thing. For example, it doesn't work in Ext.NET v2.
    I've tryed it already about an minute ago and it's not working like I wanted to:(
    but autoload = true will load store It's not good for my site performance. that's why I want to load it only on show
  8. #8
    Quote Originally Posted by ViDom View Post
    I've tryed it already about an minute ago and it's not working like I wanted to:(
    Please demonstrate what exactly you tried.


    Quote Originally Posted by ViDom View Post
    but autoload = true will load store It's not good for my site performance. that's why I want to load it only on show
    Do you think loading a single item will affect the performance?
  9. #9
    Quote Originally Posted by Daniil View Post
    Please demonstrate what exactly you tried.




    Do you think loading a single item will affect the performance?
    I have made like
    mycontrol.ComboBox.Value = 1;
    mycontrol.ComboBox.Text = "Item 1";
    It seems to be a situation that 2 properties contains same reference to the value.

    Is it make on purpose or maybe there is a "ninja" bug?

    It display text but in
    mycontrol.ComboBox.SelectedItem.Value
    is a Text value not Value ( i mean "Item 1" instead 1)
    single item won't affect performance but 3-5 it can affect performance.
    Last edited by ViDom; Dec 14, 2012 at 11:31 AM.
  10. #10
    Quote Originally Posted by ViDom View Post
    I have made like
    mycontrol.ComboBox.Value = 1;
    mycontrol.ComboBox.Text = "Item 1";
    It seems to be a situation that 2 properties contains same reference to the value.

    Is it make on purpose or maybe there is a "ninja" bug?

    It display text but in
    mycontrol.ComboBox.SelectedItem.Value
    is a Text value not Value ( i mean "Item 1" instead 1)
    As I mentioned before it is a tricky thing.

    Quote Originally Posted by ViDom View Post
    single item won't affect performance but 3-5 it can affect performance.
    Why 3-5 if you need just the only one?
    Last edited by Daniil; Dec 14, 2012 at 11:45 AM.
Page 1 of 2 12 LastLast

Similar Threads

  1. [CLOSED] Always selected Item is nothing for combobox as menu item
    By rnachman in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Sep 04, 2011, 4:51 PM
  2. [CLOSED] get the value of the selected item from a combobox via js
    By Edward in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Oct 03, 2010, 12:06 PM
  3. Get Combobox Selected item
    By yarlenvas in forum 1.x Help
    Replies: 3
    Last Post: Mar 08, 2009, 2:04 PM
  4. Get ComboBox Selected Item
    By speedstepmem3 in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Nov 18, 2008, 9:50 AM
  5. Replies: 7
    Last Post: Nov 12, 2008, 9:53 PM

Tags for this Thread

Posting Permissions