Accessing Repeater's DataSource from a UserControl inside the ItemTemplate


D

digitaljeebus

*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!
 
Ad

Advertisements


Top