Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Accessing Repeater's DataSource from a UserControl inside the ItemTemplate

Reply
Thread Tools

Accessing Repeater's DataSource from a UserControl inside the ItemTemplate

 
 
digitaljeebus@gmail.com
Guest
Posts: n/a
 
      06-13-2006
*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!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
usercontrol inside usercontrol Spartaco ASP .Net 0 07-31-2007 09:15 AM
Getting a property of a control inside a usercontrol, from another usercontrol Fabiano ASP .Net 2 06-03-2005 09:56 AM
can code inside a Repeater's ItemTemplate modify controls in the ItemTemplate? Bennett Haselton ASP .Net 1 09-24-2004 01:59 AM
Access a control inside an usercontrol from another control inside another usercontrol nail ASP .Net 0 09-15-2004 03:55 PM
Can we use a usercontrol inside a usercontrol Rajesh Tiwari ASP .Net 0 08-12-2003 03:56 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57