I have a small issue with editor part, i cannot persist the selected item, here is the code:
EditorPart:
protected override void CreateChildControls()
{
base.CreateChildControls();
ddl= new DropDownList();
webPartsList.Items.Add(new ListItem("default", "0"));
//FILLS UP THE DDL
this.controlPanel.Controls.Add(ddl);
}
public override void SyncChanges()
{
EnsureChildControls();
WebPartListing hostingWebPart = this.WebPartToEdit as WebPartListing;
if (hostingWebPart.SelectedItem == null)
{
return;
}
string selectedValue = hostingWebPart.SelectedItem.Value;
ListItem listItem = webPartsList.Items.FindByValue(selectedValue);
if (listItem != null)
{
listItem.Selected = true;
}
}
public override bool ApplyChanges()
{
EnsureChildControls();
WebPartListing hostingWebPart = this.WebPartToEdit as WebPartListing;
if (webPartsList.SelectedItem != null)
{
hostingWebPart.SelectedItem = webPartsList.SelectedItem;
}
return true;
}
So when reading some logs i know that in Apply changes the values are being set so it is ok (in ApplyChanges), But still in webpart class ListItem selectedItem is null
Here the code from webpart:
public ListItem SelectedItem { get; set; }
protected override void CreateChildControls()
{
if (SelectedItem == null)
{
return;
}
Panel div = new Panel();
div.ID = "SancoDefaultWebPartContext";
div.Controls.Add(new LiteralControl("Text: "+SelectedItem.Text));
this.Controls.Add(div);
}
So basically the issue is that i didnt see anything printed on the page, as it says the SelectedItem is null and it exits. Second issue is that I dont get the correct item selected when i'm back to editors part, alwyas default is selected, althought i say that listitem.selected=true.
I hope anyone can help me, thanks
A small update, but if i set some public string selectedText and try to print it on the page, it does work. Can it be that i cannot persist ListItems objects?