[CLOSED] Multi Combo select items from code behind

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] Multi Combo select items from code behind

    hello, I would like to know how to check items of a multicombo from codebehind, I tried use setValue and
    multicombo1.SelectedItems.Add(new Ext.Net.ListItem("1"));
    but this does not check the item with the value "1"..
    Thanks
    Last edited by Baidaly; May 17, 2013 at 7:53 PM. Reason: [CLOSED]
  2. #2
    Hello!

    This sample works fine for me:

    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <script runat="server">
            protected void Page_Load(object sender, EventArgs e)
            {
                MyCombo.SelectedItems.Add(new Ext.Net.ListItem("1"));
                MyCombo.SelectedItems.Add(new Ext.Net.ListItem("2"));
            }
        </script>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            
            <ext:MultiCombo ID="MyCombo" runat="server" Width="260">
                <Items>
                    <ext:ListItem Text="Item 1" Value="1" />
                    <ext:ListItem Text="Item 2" Value="2" />
                    <ext:ListItem Text="Item 3" Value="3" />
                    <ext:ListItem Text="Item 4" Value="4" />
                    <ext:ListItem Text="Item 5" Value="5" />
                </Items>
            </ext:MultiCombo>
        </form>
    </body>
    </html>
    Can you say your Ext.NET version?
  3. #3
    Quote Originally Posted by Baidaly View Post
    Hello!

    This sample works fine for me:

    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <script runat="server">
            protected void Page_Load(object sender, EventArgs e)
            {
                MyCombo.SelectedItems.Add(new Ext.Net.ListItem("1"));
                MyCombo.SelectedItems.Add(new Ext.Net.ListItem("2"));
            }
        </script>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            
            <ext:MultiCombo ID="MyCombo" runat="server" Width="260">
                <Items>
                    <ext:ListItem Text="Item 1" Value="1" />
                    <ext:ListItem Text="Item 2" Value="2" />
                    <ext:ListItem Text="Item 3" Value="3" />
                    <ext:ListItem Text="Item 4" Value="4" />
                    <ext:ListItem Text="Item 5" Value="5" />
                </Items>
            </ext:MultiCombo>
        </form>
    </body>
    </html>
    Can you say your Ext.NET version?
    The version is 2.1.1, I tried it but no luck
  4. #4
    Hi,

    The @Baidaly's example works fine for me with Ext.NET v2.1.1 release, but it would be better to do it like this:
    MyCombo.SelectedItems.Add(new Ext.Net.ListItem() { Value = "1" });
    Please provide your test case.

    Maybe, your Values are integers, aren't? If so, please try this:
    MyCombo.SelectedItems.Add(new Ext.Net.ListItem() { Value = 1 });
    or
    MyCombo.SelectedItems.Add(new Ext.Net.ListItem(1));
    Last edited by Daniil; May 15, 2013 at 11:46 AM.
  5. #5
    Quote Originally Posted by Daniil View Post
    Hi,

    The @Baidaly's example works fine for me with Ext.NET v2.1.1 release, but it would be better to do it like this:
    MyCombo.SelectedItems.Add(new Ext.Net.ListItem() { Value = "1" });
    Please provide your test case.

    Maybe, your Values are integers, aren't? If so, please try this:
    MyCombo.SelectedItems.Add(new Ext.Net.ListItem() { Value = 1 });
    or
    MyCombo.SelectedItems.Add(new Ext.Net.ListItem(1));
    It doesnt work, I tried your examples and it works, but I used a store to bind the data, and I am still can not select items..
    this is my example:
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default4.aspx.cs" Inherits="Default4" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <!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 runat="server" />
             
             <ext:Store ID="Store1" runat="server">
                    <Model>
                        <ext:Model ID="Model1" runat="server">
                            <Fields>
                                <ext:ModelField Name="id" />
                                <ext:ModelField Name="nombre" />
                            </Fields>
                        </ext:Model>
                    </Model>
                </ext:Store>
            
            <ext:MultiCombo ID="MyCombo" runat="server" Width="260" StoreID="Store1" ValueField="id" DisplayField="nombre">
              
            </ext:MultiCombo>
        </div>
        </form>
    </body>
    </html>
    and this is the page load

     protected void Page_Load(object sender, EventArgs e)
        {
            
         if(!IsPostBack)
            {
                Store1.DataSource = new object[]
                {
                    new object [] {1, "ana"},
                    new object [] {2, "juan"},
                    new object [] {3, "maria"}
                };
                Store1.DataBind();
    
                MyCombo.SelectedItems.Add(new Ext.Net.ListItem("2"));
                //MyCombo.SelectedItems.Add(new Ext.Net.ListItem(2));  doesnt work it needs a string
            }
        }
  6. #6
    Quote Originally Posted by Daniil View Post
    Hi,

    The @Baidaly's example works fine for me with Ext.NET v2.1.1 release, but it would be better to do it like this:
    MyCombo.SelectedItems.Add(new Ext.Net.ListItem() { Value = "1" });
    Please provide your test case.

    Maybe, your Values are integers, aren't? If so, please try this:
    MyCombo.SelectedItems.Add(new Ext.Net.ListItem() { Value = 1 });
    or
    MyCombo.SelectedItems.Add(new Ext.Net.ListItem(1));
    As @Daniil said, you should use the following because you use integers:

    MyCombo.SelectedItems.Add(new Ext.Net.ListItem(2));
  7. #7
    I tried use
    MyCombo.SelectedItems.Add(new Ext.Net.ListItem(1));
    but Ext.Net.ListItem parameter needs a string, I got the error cant convert a int into string ...
    it could be the version of ext.net?
    Last edited by rookie; May 16, 2013 at 11:48 PM.
  8. #8
    Quote Originally Posted by rookie View Post
    I tried use
    MyCombo.SelectedItems.Add(new Ext.Net.ListItem(1));
    but Ext.Net.ListItem parameter needs a string, I got the error cant convert a int into string ...
    it could be the version of ext.net?
    Yes, we added new constructor for ListItem in Ext.NET 2.2. In this case you should use only string IDs:

    public void Page_Load(object sender, EventArgs e)
        {
    
            if (!IsPostBack)
            {
                Store1.DataSource = new object[]
               {
                   new object [] {"1", "ana"},
                   new object [] {"2", "juan"},
                   new object [] {"3", "maria"}
               };
                Store1.DataBind();
    
                MyCombo.SelectedItems.Add(new Ext.Net.ListItem("2"));
            }
     
        }
  9. #9
    Yes, It works!! .. but I think I can check the items only into the Page Load or a Direct Event function, I tried to do it in a void function beacuse I am using a user control and need a set function with a parameter.
    Thank you.
    Last edited by rookie; May 17, 2013 at 5:02 PM.
  10. #10
    Does it not work for you?

    Quote Originally Posted by Daniil View Post
    Maybe, your Values are integers, aren't? If so, please try this:
    MyCombo.SelectedItems.Add(new Ext.Net.ListItem() { Value = 1 });
Page 1 of 2 12 LastLast

Similar Threads

  1. Multi combo first time select - problem
    By ssenthil21 in forum 1.x Help
    Replies: 1
    Last Post: Sep 21, 2011, 8:55 AM
  2. [CLOSED] Is it possible to Select Items of a multi select during ajax event
    By vedagopal2004 in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Jul 29, 2010, 6:28 PM
  3. Replies: 0
    Last Post: Feb 01, 2010, 12:42 PM
  4. Multi select items text not visible
    By ajaybabu.maddinani in forum 1.x Help
    Replies: 2
    Last Post: Dec 08, 2009, 7:49 AM
  5. Multi Select select/deselect
    By Palash in forum 1.x Help
    Replies: 2
    Last Post: Sep 18, 2009, 3:49 AM

Tags for this Thread

Posting Permissions