views:

335

answers:

3

ive been searching throughout msdn, but i dont know what I should be searching for exactly...how do I access the child elements of a user control, I do not wish to create a new custom control that renders its own html, the html output is a simple repeater in an ascx file, it looks like this:

<asp:repeater id="rpContent" runat="server" onitemdatabound="rpContent_itemdatabound">
    <headertemplate><ul class="displaypanel"></headertemplate>
    <itemtemplate>
     <li class="on">
      <a href="javascript://">tab header</a>
      <div>
       what goes here is tab content
      </div>
     </li>
    </itemtemplate>
    <footertemplate>
     </ul></footertemplate>
</asp:repeater>

I want implementation to look like this:

<bni:tabs id="tabs" runat="server">
    <tab srcId="id1" />
    <tab srcId="id2" />
</bni:tabs>

so basically in the code behind, i want to retrieve the collection of children in an array or list, and do some work with the ids, then bind the result set to my repeater...

A: 

I believe what you're looking for is databinding to a list.

                <ItemTemplate>
                    <tr>
                        <td> <%# DataBinder.Eval(Container.DataItem, "Name") %></td>
                        <td> <%# DataBinder.Eval(Container.DataItem, "Ticker") %></td>
                    </tr>
                </ItemTemplate>

And in the codebehind:

    class theData { public string Name { get; set; } public string Ticker { get; set; } }
var source = new List<theData>();
rpContent.DataSource = source;
rpContent.DataBind();
Ben Fulton
no im not, i want to retreive the list of tabs then bind it to an unternal repeater
Ayyash
A: 

Then do you want to access it as a child control?

    protected void rpContent_itemdatabound(object sender, EventArgs e)
    {
        var theTabs = rpContent.FindControl("tabs") as tabs;
        if (theTabs != null)
            ...
    }
Ben Fulton
nope, i dont want to access a repeaters chhild, i want to access a control's child
Ayyash
A: 

I found the solution, again, on my own!

in ascx code behind

[ParseChildren(true,"MyTabs")]
public partial class QucikTabsControl :  System.Web.UI.UserControl
{

    private List<Tab> _myTabs;
    [PersistenceMode(PersistenceMode.InnerProperty)]
    public List<Tab> MyTabs
    {
     get
     {
      if (_myTabs == null)
      {
       _myTabs =  new List<Tab>();
      }
      return _myTabs;
     }

    }
}
protected void Page_Load(object sender, EventArgs e)
{
    MyRepeater.DataSource = MyTabs.ToArray();
    MyRepeater.DataBind();
}

somehwere in app_code cs files

public class Tab
    {
    private string _sectionId;

    public Tab(): this(String.Empty)
     {
     }
    public Tab(string sectionid)
    {
     _sectionId = sectionid;
    }

    [Category("Behavior"),
    DefaultValue(""),
    Description("Section Id"),
    NotifyParentProperty(true),
    ]
    public String SectionId
    {
     get
     {
      return _sectionId;
     }
     set
     {
     _sectionId = value;
     }
    }
}

in your aspx page

<bni:tabs id="s" runat="server">
    <w:tab sectionid="23" />
</bni:tabs>

the reason im going into this trouble is basic: i am a front end developer, dont want to see a single html tag in code behind!

Ayyash