I'm desinging a rich repeater control which needs some controls (specifically just an unordered list) added to it at runtime.
The solution I've opted for is to inject the nesseccary markup, onInit, into the header, item and footer templates respectively.
I can get the templates out (using InstantiateIn) and then add the markup as needed, but I don't know a way to add the template back in to the repeater?
views:
3454answers:
2
+1
A:
In the past I've simply handled the ItemDataBound Event
and modified the current RepeaterItem
with whatever I needed to do.
Example:
private void Repeater1_ItemDataBound(object Sender, RepeaterItemEventArgs e)
{
// Make sure you filter for the item you are after
if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
{
PlaceHolder listLocation = (PlaceHolder)e.Item.FindControl("listPlaceHolder");
var subItems = ((MyClass)e.Item.DataItem).SubItems;
listLocation.Controls.Add(new LiteralControl("<ul>");
foreach(var item in subItems)
{
listLocation.Controls.Add(new LiteralControl("<li>" + item + "</li>"));
}
listLocation.Controls.Add(new LiteralControl("</ul>");
}
}
Aydsman
2008-11-07 11:47:25
Would i be able to do this from within the composite control?
Adam Naylor
2008-11-07 11:55:26
I'm not sure where your confusion is here Adam. Perhaps you can edit your question and add a bit of code or a further explaination.
Aydsman
2008-11-10 00:04:26
A:
I am also trying to build a similar custom control by extending FormViewControl and I want to add controls into the template Sections(InsertItemTemplate, EditItemTemplate, ItemTemplate) during the design time by using automated script I mean using a class which extends from FormViewDesigner class. but I couldn't achieve it. Need help in adding controls to the Templates of the Custom Control during design time.
Note. I dont want to drag and drop control in design time but rather the designer should do it automatically based on some logic.
@Adam: Please help me out if you have an answer
Shafeer
2009-12-18 05:21:32