Helllo,
I created a custom field which is a multiple lookup filed. It shows the binded data and under there is a form to add a new data. My problem is with the Button to delete each item in the list. I show you the code and put some comments to explain the problem:
Where should I put the ShowSubFormList() method so that it works after a refresh and the Event works too?
Thanks!
I created a custom field which is a multiple lookup filed. It shows the binded data and under there is a form to add a new data. My problem is with the Button to delete each item in the list. I show you the code and put some comments to explain the problem:
Code:
public class ListSubFormControl : MultipleLookupField
{
// The field containing the IDs of the lookup field
public override object Value
{
set
{
EnsureChildControls();
SPFieldLookupValueCollection lookupValues = value as SPFieldLookupValueCollection;
if (lookupValues != null)
{
foreach (SPFieldLookupValue fieldValue in lookupValues)
{
// I fill a lookup list with the IDs
lookupList.Items.Add(new ListItem(fieldValue.LookupValue,fieldValue.LookupId.ToString()));
}
}
}
}
// The method called to create the list of all binded data
public void ShowSubFormList()
{
foreach (ListItem item in lookupList.Items)
{
/* ... other code not showed here ... */
// We create a delete button for each binded data
ImageButton delItem = new ImageButton();
delItem.ImageUrl = "/_layouts/images/delete.gif";
delItem.Click += new ImageClickEventHandler(delItem_Click);
oCellLabel = new TableCell();
oCellLabel.CssClass = "ms-formbody";
rowItem.Cells.Add(oCellLabel);
oCellLabel.Controls.Add(delItem);
}
}
void delItem_Click(object sender, ShowSubFormList(), e)
{
// the code to delete the item
}
protected override void CreateChildControls()
{
// If I call the ShowSubFormList(), the value isn't set and the list will be empty
}
protected override void OnLoad(EventArgs e)
{
// If I call the ShowSubFormList() here, it's working but after a delItem_Click, the deleted item will be still in the list...
}
protected ovverride void OnPreRender(EventArgs e)
{
// If I call the ShowSubFormList() here, the list is the right list (I also have a button to add a new item and after an insert, it's the correct list), put the delete ImageButton no more working -> the event on the Click() never called...
}
}
Where should I put the ShowSubFormList() method so that it works after a refresh and the Event works too?
Thanks!