Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Problem: Nested Repeater won't databind()?

Reply
Thread Tools

Problem: Nested Repeater won't databind()?

 
 
Colin Nicholls
Guest
Posts: n/a
 
      01-12-2005
Platform: ASP.NET 1.1

I have a repeater nested inside another repeater. My outer repeater is
looping fine. I am manually binding the inner repeater to a DataReader
obtained from another function.

My objects aren't null, my ItemDataBound() method is being called, and as
you can see I have verified that I have data.

Yet, the repeater does not appear in the final HTML, and what's more, after
the DataBind() call, the .Items.Count property is still 0. What am I doing
wrong?

Here is the code (I apologise for any text wrapping - is there a way to turn
that off?):

//------------------------------------------
protected void OuterRepeater_ItemDataBound( object sender,
System.Web.UI.WebControls.RepeaterItemEventArgs e )
{

System.Web.UI.WebControls.ListItemType lt = e.Item.ItemType ;

if ( lt == System.Web.UI.WebControls.ListItemType.Item ||
lt == System.Web.UI.WebControls.ListItemType.Alternating Item )
{

System.Web.UI.WebControls.Repeater innerRepeater ;

System.Data.Common.DbDataRecord dr = e.Item.DataItem as
System.Data.Common.DbDataRecord ;
if ( dr != null)
{
string cChildKeyValue = dr["CHILD_KEY"].ToString() ;

System.Data.SqlClient.SqlDataReader oReader =
this.getChildDataFor( cChildKeyValue ) ;
if ( oReader != null )
{
innerRepeater = e.Item.FindControl("InnerRepeater") as
Repeater ;
if ( rptrGlassPart != null )
{
// Prove we have the right data:
if ( false ) {
while( oReader.Read() )
{
Response.Write( "<div>Data: " +
oReader.GetString(0) + "</div>" );
}
}
else {
// These statements appear to have no effect.
// The repeater is not rendered in the output HTML:

innerRepeater.DataSource = oReader ;
innerRepeater.DataBind() ;

// innerRepeater.Items.Count = 0 at this point.
}
}
else {
Response.Write("<div>innerRepeater is null.</div>") ;
}
oReader.Close();
}
}
}
}
//------------------------------------------

Thanks in advance,
- Colin


 
Reply With Quote
 
 
 
 
Karl Seguin
Guest
Posts: n/a
 
      01-12-2005
I can't say that I see anything inherently wrong, I imagine that the
innerRepeater is actually named rptrGlassPart as you still have a reference
to it in your code. You could use some better try/catch and god only
knows where your connections are being closed for the inner repeater's
datareader...but that shouldn't be a problem. I'd also wonder if using a
dataset with 2 datatables and a DataRelation wouldn't make things more clear
(and maybe even more performant) but again I can't see that as being the
actual problem.

Perhaps its soemthing wrong with the html side of the repeater?

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/


"Colin Nicholls" <(E-Mail Removed)> wrote in message
news:eT0fGaM%(E-Mail Removed)...
> Platform: ASP.NET 1.1
>
> I have a repeater nested inside another repeater. My outer repeater is
> looping fine. I am manually binding the inner repeater to a DataReader
> obtained from another function.
>
> My objects aren't null, my ItemDataBound() method is being called, and as
> you can see I have verified that I have data.
>
> Yet, the repeater does not appear in the final HTML, and what's more,

after
> the DataBind() call, the .Items.Count property is still 0. What am I doing
> wrong?
>
> Here is the code (I apologise for any text wrapping - is there a way to

turn
> that off?):
>
> //------------------------------------------
> protected void OuterRepeater_ItemDataBound( object sender,
> System.Web.UI.WebControls.RepeaterItemEventArgs e )
> {
>
> System.Web.UI.WebControls.ListItemType lt = e.Item.ItemType ;
>
> if ( lt == System.Web.UI.WebControls.ListItemType.Item ||
> lt == System.Web.UI.WebControls.ListItemType.Alternating Item )
> {
>
> System.Web.UI.WebControls.Repeater innerRepeater ;
>
> System.Data.Common.DbDataRecord dr = e.Item.DataItem as
> System.Data.Common.DbDataRecord ;
> if ( dr != null)
> {
> string cChildKeyValue = dr["CHILD_KEY"].ToString() ;
>
> System.Data.SqlClient.SqlDataReader oReader =
> this.getChildDataFor( cChildKeyValue ) ;
> if ( oReader != null )
> {
> innerRepeater = e.Item.FindControl("InnerRepeater") as
> Repeater ;
> if ( rptrGlassPart != null )
> {
> // Prove we have the right data:
> if ( false ) {
> while( oReader.Read() )
> {
> Response.Write( "<div>Data: " +
> oReader.GetString(0) + "</div>" );
> }
> }
> else {
> // These statements appear to have no effect.
> // The repeater is not rendered in the output

HTML:
>
> innerRepeater.DataSource = oReader ;
> innerRepeater.DataBind() ;
>
> // innerRepeater.Items.Count = 0 at this point.
> }
> }
> else {
> Response.Write("<div>innerRepeater is null.</div>") ;
> }
> oReader.Close();
> }
> }
> }
> }
> //------------------------------------------
>
> Thanks in advance,
> - Colin
>
>



 
Reply With Quote
 
 
 
 
Colin Nicholls
Guest
Posts: n/a
 
      01-12-2005
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:e35kFnM%(E-Mail Removed)...

> I can't say that I see anything inherently wrong, I imagine that the
> innerRepeater is actually named rptrGlassPart as you still have a
> reference to it in your code.


oops! Yes, sorry, I simplified the posted code and missed a reference.


> You could use some better try/catch and god only
> knows where your connections are being closed for the inner repeater's
> datareader...but that shouldn't be a problem.


I took out some of the try/catch and debug code for simplification. The
connections (several in total) are all being closed in Page_Unload().


> I'd also wonder if using a dataset with 2 datatables and a DataRelation
> wouldn't make things more clear (and maybe even more performant) but
> again I can't see that as being the actual problem.


My associate suggested that as well, but this is a simplified case of a
multi-child entity problem so changing to related data sets wouldn't solve
everything. I just felt that this should work - inefficient as it may be -
and it wasn't.


> Perhaps its soemthing wrong with the html side of the repeater?


If so, I can't figure it out. I have other (not nested) repeaters elsewhere
in my aspx that are working fine, binding to DataReaders using the same
mechanism.

Thanks for verifying that it's not a simple newbie error. I have several
options to try.

1) bind the innerRepeater to a dataset instead of a reader (who knows? might
work)

2) use an inner DataGrid instead of a Repeater, bind it to the Reader
(ditto)

3) work up a REALLY simple nested Repeater example to see if it shows the
same problem.

Thanks again, Karl,
- Colin



 
Reply With Quote
 
lcr lcr is offline
Junior Member
Join Date: Jul 2008
Posts: 1
 
      07-08-2008
Probably too late to help you with this issue Colin but maybe this will help others.

I've been having this same problem for ages with nested repeaters - couldn't get any of the events for the "child" repeater to fire from code behind and had to populate the repeater's values with <%DataBinder.Eval...%> on the apsx page which wasn't possible for more complicated databinding.

I finally found that adding the name of the event handler in the "OnItemDataBound" attribute of the repeater on the aspx page made the event fire in the code behind.

e.g. <asp:Repeater ID="rptCustomSectionLine" OnItemDataBound="rptCustomSectionLine_ItemDataBoun d" Runat="server">

Cheers
Lisa
 
Reply With Quote
 
codelavie codelavie is offline
Junior Member
Join Date: Nov 2009
Posts: 1
 
      11-09-2009
Thanks Lisa, it helped me.
 
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
repeater inside a repeater problem. uncensored ASP .Net 0 10-25-2006 06:10 PM
Repeater inside a Repeater Microsoft ASP .Net Web Controls 0 08-21-2006 09:13 AM
Repeater inside a repeater....how? voidfill3d@yahoo.com ASP .Net 1 08-10-2005 01:58 PM
Repeater Using Javascript Referencing a Column in the Repeater rwoo_98@yahoo.com ASP .Net 0 02-26-2005 05:02 PM
Repeater control with nested repeater chris.reed@digus.com ASP .Net 0 02-11-2005 05:10 PM



Advertisments