[CLOSED] Multicombo Items

  1. #1

    [CLOSED] Multicombo Items

    Hi.

    I have a multicombo populated with at least 5 items.
    I select many of them and need to iterate server side throught all items and check for selection so to persist a many to many collection.

    For each Item in Combo check if it is selected. If so, check if it is added to the Entity, if not, Add.
    If it is not selected, check if it is in entity. If so, remove.

    The problem is that I am getting no Items in Combo.Items, but I am getting all Combo.SelectedItems.

    Control in aspx
    <ext:MultiCombo ID="mcmbCategories" runat="server" SelectionMode="All" Width="300" FieldLabel="Categories"
                    DisplayField="Category_Name"
                                         ValueField="Category _Id"
                                           EmptyText="Select one or many"
                                              Editable="false"
                                               TypeAhead="false">
                        <Store>
                            <ext:Store ID="CategoryStore" runat="server" DataSourceID="CategoryList" OnRefreshData="CategoryRefresh">
                                <Reader>
                                    <ext:JsonReader IDProperty="Category _Id">
                                        <Fields>
                                            <ext:RecordField Name="Category _Name" />
                                            <ext:RecordField Name="Category _Id" />
                                        </Fields>
                                    </ext:JsonReader>
                                </Reader>
                               
                            </ext:Store>
                        </Store>
                    </ext:MultiCombo>

    Code behind

    Refreshing method:
    Public Sub CategoryRefresh(ByVal sender As Object, ByVal e As StoreRefreshDataEventArgs)
    
    
            mcmbCategories.DataBind()
    
    
        End Sub
    Items iteration
    
               '"pPhone" is arriving by parameter as an instance of Phone entity.
    
              For Each mItem As ListItem In mcmbCategories.Items     '<--- HERE, NO ITEMS RETURNED. "FOR" BYPASSED
    
    
                Dim mVal As String = mItem.Value
                Dim mSelected As Boolean = False
    
                'DEBUGGING I CHECK THAT SelectedItems DOES RETURN ALL SELECTED ITEMS
                If (From mSel As SelectedListItem In mcmbCategories.SelectedItems Select mSel Where mSel.Value = mVal).Count > 0 Then
                    'Its selected
                    mSelected = True
                End If
    
    
                Dim mCat As Category = (From cc As Category In pPhone.Categories Select cc Where cc.Id = mVal).FirstOrDefault
                
                If Not IsNothing(mCat) Then
                    'Category already in phone
    
    
                    If Not mSelected Then
                        pPhone.Categories.Delete(mCat)
                    End If
                Else
                    'Not in phone yet
    
    
                    If mSelected Then
                        pPhone.Categories.Add(New Category (mItem.Value))
                    End If
                End If
    
    
            Next
    Also I am checking regular Items against SelectedItems using Linq because I couldn't find a way to check if the Item is selected or not (something like mItem.IsSelected)

    Thanks
    Regadrs
    Fernando
    Last edited by Daniil; Mar 14, 2012 at 7:27 AM. Reason: [CLOSED]
  2. #2
    Hi,

    Quote Originally Posted by FAS View Post
    The problem is that I am getting no Items in Combo.Items
    Yes, because you populate the MultiCombo via Store. An Items collection is not populated automatically.

    You should get these Items from the CategoryList DataSource.
  3. #3
    Thanks.

    Any helpful code?

    You mean this?

    For Each mItem as ListItem in CategoryList.Store(0).WhatAttribute???
    
           mItem.ValueOrWhatField???   (then I need the value for each listed item (selected or not)
    I guess ListItem shouldn't be the listed type.

    Will the store get refreshed for this iteration?

    I would like to iterate throught items just as they are in client at the submit moment.

    Thanks
    Regrds
    Fernando
  4. #4
    I meant iterating the DataSource object.

    I would like to iterate throught items just as they are in client at the submit moment.
    I can suggest this way to get all Items values.

    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.MultiCombo1.GetStore();
                store.DataSource = new object[] 
                { 
                    new object[] { "1", "item1" },
                    new object[] { "2", "item2" },
                    new object[] { "3", "item3" }
                };
                store.DataBind();
            }
        }
    
        protected void Submit(object sender, DirectEventArgs e)
        {
            string itemsJson = e.ExtraParams["items"];
            Dictionary<string, string>[] dictItems = JSON.Deserialize<Dictionary<string, string>[]>(itemsJson);
            SelectedListItemCollection items = JSON.Deserialize<SelectedListItemCollection>(itemsJson);
    
            string result = "";
    
            foreach (Ext.Net.SelectedListItem item in items) 
            {
                result += string.Format("Value: {0}<br/>", item.Value);
            }
    
            X.Msg.Alert("Submit", result).Show();
        }
    </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:MultiCombo ID="MultiCombo1" runat="server">
                <Store>
                    <ext:Store runat="server">
                        <Reader>
                            <ext:ArrayReader>
                                <Fields>
                                    <ext:RecordField Name="value" />
                                    <ext:RecordField Name="text" />
                                </Fields>
                            </ext:ArrayReader>
                        </Reader>
                    </ext:Store>
                </Store>
            </ext:MultiCombo>
            <ext:Button runat="server" Text="Submit">
                <DirectEvents>
                    <Click OnEvent="Submit">
                        <ExtraParams>
                            <ext:Parameter 
                                Name="items" 
                                Value="MultiCombo1.getStore().getRecordsValues({ excludeId : true })" 
                                Mode="Raw" 
                                Encode="true" />
                        </ExtraParams>
                    </Click>
                </DirectEvents>
            </ext:Button>
        </form>
    </body>
    </html>
  5. #5
    Thanks

    That works, anyway I thought it could be more straightforward.

    In this particular case I decided to just get all data again to iterate all categories (as Categories are a few, they are cached in dataCache)

    Anyway, for more heavy queries I'll think better to implement this solution.

    Thanks
    Regards
    Fernando

Similar Threads

  1. MultiCombo not returning any selected items
    By dtamils in forum 1.x Help
    Replies: 3
    Last Post: Feb 27, 2013, 3:56 AM
  2. [CLOSED] Multicombo with a lot of items
    By sadaf in forum 1.x Legacy Premium Help
    Replies: 7
    Last Post: Oct 20, 2011, 1:32 PM
  3. [CLOSED] MultiCombo doesn't select items with comma in text
    By acrossdev in forum 1.x Legacy Premium Help
    Replies: 11
    Last Post: Oct 19, 2010, 6:56 AM
  4. [CLOSED] Can't select items from multicombo
    By webclouder in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Jun 21, 2010, 10:10 AM
  5. [1.0] MultiCombo how to return items.count
    By steve.redmon in forum 1.x Help
    Replies: 0
    Last Post: Jun 11, 2010, 9:51 PM

Tags for this Thread

Posting Permissions