Mar 13, 2012, 2:40 PM
[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
Code behind
Refreshing method:
Thanks
Regadrs
Fernando
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]