Accessing Repeater's DataSource from a UserControl inside the ItemTemplate

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

  1. Guest

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

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

    // relevant code
    protected void rpt1_ItemDataBound(object sender, RepeaterItemEventArgs
    e)
    {
    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";
    else
    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 asp.net 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!
     
    , Jun 13, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. nail
    Replies:
    0
    Views:
    1,546
  2. Bennett Haselton
    Replies:
    1
    Views:
    5,341
    Joe Fallon
    Sep 24, 2004
  3. HockeyFan
    Replies:
    1
    Views:
    999
    Masudur
    Jul 4, 2007
  4. Oleg
    Replies:
    1
    Views:
    7,339
    Cowboy \(Gregory A. Beamer\)
    Mar 7, 2008
  5. Andy B
    Replies:
    1
    Views:
    993
    bruce barker
    Nov 15, 2008
Loading...

Share This Page