Wednesday, March 28, 2012

Change CollapsiblePanelExtender properties programatically within a DataList

I'm currently using CollapsiblePanelExtender within a DataList. The DataList contains a Label where the user will select to expand/contract theCollapsiblePanelExtender. TheCollapsedproperty withinCollapsiblePanelPropertiesis set tofalse. I would like to expandonly the first panel in the DataList when the page loads while the remaining panels remain collapsed.

I am intending to set theCollapsiblePanelPropertiesto true for the first item in the DataList within the DataList1_ItemDataBound event. How do I reference theCollapsiblePanelProperties as it does not contain an ID likeCollapsiblePanelExtender as I can not perform the following?

CollapsiblePanelProperties cpp =newCollapsiblePanelProperties();

cpp = (CollapsiblePanelProperties)e.Item.FindControl("CollapsiblePanelProperties");

Is there a different approach? Thanks in advance.

This has come up a couple of times in the past few days. A good solution when it works is something like "Extender1.GetTargetProperties(Control1)". I think that will work here, so please give it a try!

Thanks David. Extender1.GetTargetProperties(Control1) works!

Control1 being the TargetControlID of the CollapsiblePanelProperties. In my sample, Control1 is Panel1. Here is the code within the DataList1_ItemDataBound event for everyone...

if

(e.Item.ItemType ==ListItemType.Item){ CollapsiblePanelExtender ce =newCollapsiblePanelExtender();

ce = (

CollapsiblePanelExtender)e.Item.FindControl("CollapsiblePanelExtender1"); Panel pan =newPanel();

pan = (

Panel)e.Item.FindControl("Panel1"); if (e.Item.ItemIndex == 0){ CollapsiblePanelProperties cpp;

cpp = ce.GetTargetProperties(pan);

cpp.Collapsed =

false;

}

}

No comments:

Post a Comment