By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 909 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

Problem: Nested Repeater won't databind()?

P: n/a
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
Nov 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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" <co***@spacefold.com> wrote in message
news:eT****************@TK2MSFTNGP12.phx.gbl...
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

Nov 19 '05 #2

P: n/a
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:e3****************@tk2msftngp13.phx.gbl...
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

Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.