Accessing Repeater's DataSource from a UserControl inside the ItemTemplate

Discussion in 'ASP .Net Web Controls' started by digitaljeebus, Jun 13, 2006.

  1. *whew* what a title =) here's what I have now

    // relevant webpage
    <asp:Repeater runat="server" ID="rpt1">
    <div runat="server" id="myDiv" />

    // relevant code
    protected void rpt1_ItemDataBound(object sender, RepeaterItemEventArgs
    if (e.Item.ItemType == ListItemType.Item ||
    e.Item.ItemType == ListItemType.AlternatingItem)
    CustomClass item = (CustomClass)e.Item.DataItem; // this is the
    line i can't duplicate
    if (item.SomeValue == 2)
    e.Item.FindControl("myDiv").InnerText = "My Value is 2";
    e.Item.FindControl("myDiv").InnerText = "My Value is not 2";

    I want to put the div inside a user control by itself, but in a user
    control, there is no OnDataBound() method to override, or DataBound
    event to subscribe to =/ as far as i can tell, there's also no way to
    access the datasource (although you can use <%# Eval("SomeValue") %> in
    the .ascx file for some reason) ... after that, here's my question:

    is there some usercontrol-equivalent way to get at the marked line to
    get the actual databound object in the usercontrol? or do i have to do
    all my dataformatting in ugly markup <%# ... %> code blocks? i changed
    over to so i don't have to do stuff like that, and everything i
    see makes me thinks that's my only option ... i understand that i could
    find the usercontrol in my rpt1_ItemDataBound(...) method, but most of
    the usercontrols i'm creating would need either dozens of properties,
    or a lot of ugly markup, and this would make things a lot easier ... if
    anyone knows where this property is, or why it doesn't exist, please
    help me, shed some light!! thanks!
    digitaljeebus, Jun 13, 2006
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.