AI OnAI Off
Try using lbSignPost.Items.OfType<ListItem>().Where(item => item.Selected);
Hope this helps.
Frederik
Hi,
Thanks for the reply.
I tried like this:
protected override void SetupEditControls()
{
try
{
lbSignPost.SelectedValue = this.ToString();
}
catch
{
}
}
public override void ApplyEditChanges()
{
try
{
base.SetValue((lbSignPost.Items.OfType<ListItem>().Where(item => item.Selected)));
}
catch
{
}
}
This time I'm not seeing any item as selected once published, Am I missing something in "SetupEditControls()" method.
Thanks.
When setting the value (ApplyEditChanges()) you need to use a separator, comma or similar. Then when getting the value traverse through the Items and check if the item value matches the one you have stored, and based on that set Selected property to true for that item.
Frederik
Hi,
With the help of following code I'm able to do this.
protected override void SetupEditControls()
{
try
{
string strTempHideSignPostId = string.Empty;
strTempHideSignPostId=this.ToString();
List<string> lstSignPosts=new List<string>();
if (strTempHideSignPostId.Contains(","))
{
lstSignPosts = strTempHideSignPostId.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
}
else
lstSignPosts.Add(strTempHideSignPostId);
lstSignPosts.ForEach(li =>
{
if (lbSignPost.Items.OfType<ListItem>().Any(li2 => li == li2.Value))
lbSignPost.Items.OfType<ListItem>().Single(li3 => li3.Value == li).Selected = true;
});
}
catch
{
}
}
public override void ApplyEditChanges()
{
try
{
string strSelectedValue = string.Empty;
List<ListItem> LstTest = new List<ListItem>();
strSelectedValue = lbSignPost.SelectedValue;
LstTest = lbSignPost.Items.OfType<ListItem>().Where(a => a.Selected).ToList();
int itemCount = 0;
foreach (var item in LstTest)
{
if (itemCount == 0)
{
strSelectedValue = item.Value.ToString();
}
else
strSelectedValue = strSelectedValue + "," + item.Value.ToString();
itemCount++;
}
base.SetValue(strSelectedValue);
}
catch
{
}
}
Thanks.
Hi, With the following Code I'm able to create a Custom ListBox property.
I would like to use Multiple selection of the list Box. In edit mode I'm able to select multiple values, but after publishing the page I'm seeing only one value as selected value.
Please check the code and advice me what I'm missing here.
[Serializable]
[PageDefinitionTypePlugIn]
public class SignPostListBox:EPiServer.Core.PropertyString
{
public override EPiServer.Core.IPropertyControl CreatePropertyControl()
{
return new SignPostListBoxControl();
}
}
Please suggest me your Ideas.
Thanks.