tags:

views:

3454

answers:

2

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?

+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
Would i be able to do this from within the composite control?
Adam Naylor
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
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
I never actually got an elegant solution to this I'm afraid.
Adam Naylor