Jun 08, 2016, 10:38 AM
[CLOSED] Itemselector questions
Hi guys,
Trying to use the itemselector, but I have 2 questions in my test app:
Why do I need to update the selecteditems to show the (still non selected) items in the 'available' box initially ?
Why can I loop throught the .selectedItems after choosing some --> Save, but can't I loop through the .items collection because it seems to be empty ?
Where do I go wrong ? :)
.aspx
Martin
Trying to use the itemselector, but I have 2 questions in my test app:
Why do I need to update the selecteditems to show the (still non selected) items in the 'available' box initially ?
Why can I loop throught the .selectedItems after choosing some --> Save, but can't I loop through the .items collection because it seems to be empty ?
Where do I go wrong ? :)
.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="iWise3.Test.WebForm1" %>
<!DOCTYPE html>
<html>
<head runat="server">
<title>Test</title>
<style>
.label {
font : bold 11px tahoma,arial,sans-serif;
width : 300px;
height : 25px;
padding : 5px 0;
border : 1px dotted #99bbe8;
color : #15428b;
cursor : default;
margin : 10px;
background : #dfe8f6;
text-align : center;
margin-left : 0px;
}
</style>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />
<ext:FormPanel
runat="server"
Title="ItemSelector Test"
Width="700"
BodyPadding="10"
Height="450"
Layout="fit"
>
<Items>
<ext:ItemSelector
ID="ItemSelector1"
runat="server"
FieldLabel="ItemSelector"
FromTitle="Available"
ToTitle="Selected">
</ext:ItemSelector>
</Items>
<DockedItems>
<ext:Toolbar runat="server" Dock="Bottom">
<Items>
<ext:Button runat="server" Text="Save" Handler="App.direct.SaveFilter()"/>
</Items>
</ext:Toolbar>
</DockedItems>
</ext:FormPanel>
</form>
</body>
</html>
.csusing System;
using System.Diagnostics;
using Ext.Net;
using ListItem = Ext.Net.ListItem;
namespace iWise3.Test
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
for (int i = 0; i < 10; i++)
{
ListItem li = new ListItem
{
Value = i.ToString(),
Text = $"Item {i}"
};
ItemSelector1.Items.Add(li);
}
//ItemSelector1.Update();
ItemSelector1.UpdateSelectedItems(); // Why is it empty without ?
}
}
[DirectMethod]
public void SaveFilter()
{
foreach (ListItem li in ItemSelector1.Items)
{
Debug.WriteLine($"Item: {li.Value}"); // Empty ???
}
foreach (ListItem sli in ItemSelector1.SelectedItems)
{
Debug.WriteLine($"Selected Item: {sli.Value}");
}
}
}
Martin