473,399 Members | 4,177 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Bug with nested repeaters. Item events are called twice per item

On my page, I have one repeater that contains a literal control and a nested
repeater. The nested repeater contains a literal control. Both repeaters
are databound with only one object (string). But... and this is the crappy
part, the nested repeater's events are fired twice. How do I know this? I
setup global private counter variables that get incremented on the repeater's
ItemDataBound event. The outer repeater is correct and only calls the
ItemDataBound event once for each item, but the inner nested repeater calls
it's ItemDataBound event twice for each item.

It's worth mentioning that I did set AutoEventWireup to false, just in case...

You can review the markup and code or download the code
(http://www.biasecurities.com/files/f...ownload.aspx):

Default.aspx only has:

<asp:repeater ID="OuterRepeater" runat="server">
<ItemTemplate>
Outer ItemDataBind function called <asp:Literal
ID="MyText" runat="server" /time(s)<br />

<asp:Repeater ID="InnerRepeater" runat="server">
<ItemTemplate>
Nested ItemDataBind function called
<asp:Literal ID="Text" runat="server" /time(s)<br />

</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:repeater>

Default.aspx.cs contains:

protected override void OnInit(EventArgs e)
{
OuterRepeater.ItemCreated += new
RepeaterItemEventHandler(Outer_ItemCreated);
OuterRepeater.ItemDataBound += new
RepeaterItemEventHandler(Outer_ItemDataBound);
this.Load += new EventHandler(Page_Load);
base.OnInit(e);
}

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
List<stringmyList = new List<string>();
myList.Add("1");
OuterRepeater.DataSource = myList;
OuterRepeater.DataBind();
}
}

void Outer_ItemCreated(object sender, RepeaterItemEventArgs e)
{
Repeater repeater = (Repeater)e.Item.FindControl("InnerRepeater");
if (repeater != null)
{
List<stringmyList = new List<string>();
myList.Add("1.1");
repeater.ItemDataBound += new
RepeaterItemEventHandler(Inner_ItemDataBound);
repeater.DataSource = myList;
repeater.DataBind();
}
}

int outerCount = 0;

void Outer_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
outerCount++;
string myValue = (string)e.Item.DataItem;

Literal text = (Literal)e.Item.FindControl("MyText");
if (text != null)
{
text.Text = outerCount.ToString();
}
}

int innerCount = 0;

void Inner_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
innerCount++;
string myValue = (string)e.Item.DataItem;
Literal text = (Literal)e.Item.FindControl("Text");
text.Text = innerCount.ToString();
}

So at this point, I'm just confused... is this a bug with asp.net? if so...
damn, it seems pretty major, imo. Any help would be appreciated...
Mar 15 '07 #1
4 4539
your are not checking the item type to see if its a Item or AlternateItem

-- bruce (sqlwork.com)

James Geurts wrote:
On my page, I have one repeater that contains a literal control and a nested
repeater. The nested repeater contains a literal control. Both repeaters
are databound with only one object (string). But... and this is the crappy
part, the nested repeater's events are fired twice. How do I know this? I
setup global private counter variables that get incremented on the repeater's
ItemDataBound event. The outer repeater is correct and only calls the
ItemDataBound event once for each item, but the inner nested repeater calls
it's ItemDataBound event twice for each item.

It's worth mentioning that I did set AutoEventWireup to false, just in case...

You can review the markup and code or download the code
(http://www.biasecurities.com/files/f...ownload.aspx):

Default.aspx only has:

<asp:repeater ID="OuterRepeater" runat="server">
<ItemTemplate>
Outer ItemDataBind function called <asp:Literal
ID="MyText" runat="server" /time(s)<br />

<asp:Repeater ID="InnerRepeater" runat="server">
<ItemTemplate>
Nested ItemDataBind function called
<asp:Literal ID="Text" runat="server" /time(s)<br />

</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:repeater>

Default.aspx.cs contains:

protected override void OnInit(EventArgs e)
{
OuterRepeater.ItemCreated += new
RepeaterItemEventHandler(Outer_ItemCreated);
OuterRepeater.ItemDataBound += new
RepeaterItemEventHandler(Outer_ItemDataBound);
this.Load += new EventHandler(Page_Load);
base.OnInit(e);
}

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
List<stringmyList = new List<string>();
myList.Add("1");
OuterRepeater.DataSource = myList;
OuterRepeater.DataBind();
}
}

void Outer_ItemCreated(object sender, RepeaterItemEventArgs e)
{
Repeater repeater = (Repeater)e.Item.FindControl("InnerRepeater");
if (repeater != null)
{
List<stringmyList = new List<string>();
myList.Add("1.1");
repeater.ItemDataBound += new
RepeaterItemEventHandler(Inner_ItemDataBound);
repeater.DataSource = myList;
repeater.DataBind();
}
}

int outerCount = 0;

void Outer_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
outerCount++;
string myValue = (string)e.Item.DataItem;

Literal text = (Literal)e.Item.FindControl("MyText");
if (text != null)
{
text.Text = outerCount.ToString();
}
}

int innerCount = 0;

void Inner_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
innerCount++;
string myValue = (string)e.Item.DataItem;
Literal text = (Literal)e.Item.FindControl("Text");
text.Text = innerCount.ToString();
}

So at this point, I'm just confused... is this a bug with asp.net? if so...
damn, it seems pretty major, imo. Any help would be appreciated...
Mar 16 '07 #2
I don't see how that even applies to this situation. item events should only
be called once per item regardless of if it is an Item or AlternateItem.

Anyone from MS want to help with this?

Thanks

Jim

"bruce barker" wrote:
your are not checking the item type to see if its a Item or AlternateItem

-- bruce (sqlwork.com)

James Geurts wrote:
On my page, I have one repeater that contains a literal control and a nested
repeater. The nested repeater contains a literal control. Both repeaters
are databound with only one object (string). But... and this is the crappy
part, the nested repeater's events are fired twice. How do I know this? I
setup global private counter variables that get incremented on the repeater's
ItemDataBound event. The outer repeater is correct and only calls the
ItemDataBound event once for each item, but the inner nested repeater calls
it's ItemDataBound event twice for each item.

It's worth mentioning that I did set AutoEventWireup to false, just in case...

You can review the markup and code or download the code
(http://www.biasecurities.com/files/f...ownload.aspx):

Default.aspx only has:

<asp:repeater ID="OuterRepeater" runat="server">
<ItemTemplate>
Outer ItemDataBind function called <asp:Literal
ID="MyText" runat="server" /time(s)<br />

<asp:Repeater ID="InnerRepeater" runat="server">
<ItemTemplate>
Nested ItemDataBind function called
<asp:Literal ID="Text" runat="server" /time(s)<br />

</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:repeater>

Default.aspx.cs contains:

protected override void OnInit(EventArgs e)
{
OuterRepeater.ItemCreated += new
RepeaterItemEventHandler(Outer_ItemCreated);
OuterRepeater.ItemDataBound += new
RepeaterItemEventHandler(Outer_ItemDataBound);
this.Load += new EventHandler(Page_Load);
base.OnInit(e);
}

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
List<stringmyList = new List<string>();
myList.Add("1");
OuterRepeater.DataSource = myList;
OuterRepeater.DataBind();
}
}

void Outer_ItemCreated(object sender, RepeaterItemEventArgs e)
{
Repeater repeater = (Repeater)e.Item.FindControl("InnerRepeater");
if (repeater != null)
{
List<stringmyList = new List<string>();
myList.Add("1.1");
repeater.ItemDataBound += new
RepeaterItemEventHandler(Inner_ItemDataBound);
repeater.DataSource = myList;
repeater.DataBind();
}
}

int outerCount = 0;

void Outer_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
outerCount++;
string myValue = (string)e.Item.DataItem;

Literal text = (Literal)e.Item.FindControl("MyText");
if (text != null)
{
text.Text = outerCount.ToString();
}
}

int innerCount = 0;

void Inner_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
innerCount++;
string myValue = (string)e.Item.DataItem;
Literal text = (Literal)e.Item.FindControl("Text");
text.Text = innerCount.ToString();
}

So at this point, I'm just confused... is this a bug with asp.net? if so...
damn, it seems pretty major, imo. Any help would be appreciated...
Mar 16 '07 #3
Hello? Anyone have an answer for this?

"James Geurts" wrote:
On my page, I have one repeater that contains a literal control and a nested
repeater. The nested repeater contains a literal control. Both repeaters
are databound with only one object (string). But... and this is the crappy
part, the nested repeater's events are fired twice. How do I know this? I
setup global private counter variables that get incremented on the repeater's
ItemDataBound event. The outer repeater is correct and only calls the
ItemDataBound event once for each item, but the inner nested repeater calls
it's ItemDataBound event twice for each item.

It's worth mentioning that I did set AutoEventWireup to false, just in case...

You can review the markup and code or download the code
(http://www.biasecurities.com/files/f...ownload.aspx):

Default.aspx only has:

<asp:repeater ID="OuterRepeater" runat="server">
<ItemTemplate>
Outer ItemDataBind function called <asp:Literal
ID="MyText" runat="server" /time(s)<br />

<asp:Repeater ID="InnerRepeater" runat="server">
<ItemTemplate>
Nested ItemDataBind function called
<asp:Literal ID="Text" runat="server" /time(s)<br />

</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:repeater>

Default.aspx.cs contains:

protected override void OnInit(EventArgs e)
{
OuterRepeater.ItemCreated += new
RepeaterItemEventHandler(Outer_ItemCreated);
OuterRepeater.ItemDataBound += new
RepeaterItemEventHandler(Outer_ItemDataBound);
this.Load += new EventHandler(Page_Load);
base.OnInit(e);
}

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
List<stringmyList = new List<string>();
myList.Add("1");
OuterRepeater.DataSource = myList;
OuterRepeater.DataBind();
}
}

void Outer_ItemCreated(object sender, RepeaterItemEventArgs e)
{
Repeater repeater = (Repeater)e.Item.FindControl("InnerRepeater");
if (repeater != null)
{
List<stringmyList = new List<string>();
myList.Add("1.1");
repeater.ItemDataBound += new
RepeaterItemEventHandler(Inner_ItemDataBound);
repeater.DataSource = myList;
repeater.DataBind();
}
}

int outerCount = 0;

void Outer_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
outerCount++;
string myValue = (string)e.Item.DataItem;

Literal text = (Literal)e.Item.FindControl("MyText");
if (text != null)
{
text.Text = outerCount.ToString();
}
}

int innerCount = 0;

void Inner_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
innerCount++;
string myValue = (string)e.Item.DataItem;
Literal text = (Literal)e.Item.FindControl("Text");
text.Text = innerCount.ToString();
}

So at this point, I'm just confused... is this a bug with asp.net? if so...
damn, it seems pretty major, imo. Any help would be appreciated...
Mar 24 '07 #4
Got a reply from Microsoft:

"The repeater calls databind on all its item children in the ItemDataBound
event. So the inner repeater is databound once by the outer databound, and
once by you in your Outer_ItemCreated event handler. To make the inner
repeater bind just once, remove the call to DataBind in Outer_ItemCreated."

Hope that helps someone...
"James Geurts" wrote:
On my page, I have one repeater that contains a literal control and a nested
repeater. The nested repeater contains a literal control. Both repeaters
are databound with only one object (string). But... and this is the crappy
part, the nested repeater's events are fired twice. How do I know this? I
setup global private counter variables that get incremented on the repeater's
ItemDataBound event. The outer repeater is correct and only calls the
ItemDataBound event once for each item, but the inner nested repeater calls
it's ItemDataBound event twice for each item.

It's worth mentioning that I did set AutoEventWireup to false, just in case...

You can review the markup and code or download the code
(http://www.biasecurities.com/files/f...ownload.aspx):

Default.aspx only has:

<asp:repeater ID="OuterRepeater" runat="server">
<ItemTemplate>
Outer ItemDataBind function called <asp:Literal
ID="MyText" runat="server" /time(s)<br />

<asp:Repeater ID="InnerRepeater" runat="server">
<ItemTemplate>
Nested ItemDataBind function called
<asp:Literal ID="Text" runat="server" /time(s)<br />

</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:repeater>

Default.aspx.cs contains:

protected override void OnInit(EventArgs e)
{
OuterRepeater.ItemCreated += new
RepeaterItemEventHandler(Outer_ItemCreated);
OuterRepeater.ItemDataBound += new
RepeaterItemEventHandler(Outer_ItemDataBound);
this.Load += new EventHandler(Page_Load);
base.OnInit(e);
}

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
List<stringmyList = new List<string>();
myList.Add("1");
OuterRepeater.DataSource = myList;
OuterRepeater.DataBind();
}
}

void Outer_ItemCreated(object sender, RepeaterItemEventArgs e)
{
Repeater repeater = (Repeater)e.Item.FindControl("InnerRepeater");
if (repeater != null)
{
List<stringmyList = new List<string>();
myList.Add("1.1");
repeater.ItemDataBound += new
RepeaterItemEventHandler(Inner_ItemDataBound);
repeater.DataSource = myList;
repeater.DataBind();
}
}

int outerCount = 0;

void Outer_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
outerCount++;
string myValue = (string)e.Item.DataItem;

Literal text = (Literal)e.Item.FindControl("MyText");
if (text != null)
{
text.Text = outerCount.ToString();
}
}

int innerCount = 0;

void Inner_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
innerCount++;
string myValue = (string)e.Item.DataItem;
Literal text = (Literal)e.Item.FindControl("Text");
text.Text = innerCount.ToString();
}

So at this point, I'm just confused... is this a bug with asp.net? if so...
damn, it seems pretty major, imo. Any help would be appreciated...
Mar 28 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: DonRex | last post by:
Hello all! I couldn't find a web application-newsgroup for ASP.NET, so I'm sorry if this is the wrong forum! Synopsis: In my webform I have 3 nested repeaters: rpWeeks ----- rpTime
0
by: Machi | last post by:
let say in parent-child scenerio (Product: Product Category - one product category may has many products), i am using nested repeaters where parent repeater will be used to display info and child...
2
by: Matt Jensen | last post by:
Howdy I have 2 repeaters on a C# page, 1 nested under the other. In some cases, the nested repeaters <ItemTemplate> does not contain rows - how does one display a text message in place of the...
1
by: jeremystein | last post by:
With nested repeaters, how can I access the outer repeater's DataItem from the inner repeater? Here's a snippet from my aspx: <asp:repeater id="OuterRepeater" runat="server"...
6
by: Steve Hershoff | last post by:
Hi everyone, I've got a strange one here. There are two datagrids on my page, one nested within the other. I'll refer to them as the topmost and secondary datagrids. In the topmost...
0
by: Adam Knight | last post by:
Hi All, I have a repeater control nested inside another repeater control. The nested (child) repeater control, is bound to an object data source. My problem is, i need to send a data item...
2
by: Josh | last post by:
I have a nested repeater situation with a Link Button on the nested repeater. However when the link button is clicked I get a postback but the event never takes place. I'm trying to wire up the...
1
PrinsonG
by: PrinsonG | last post by:
My Query is How do I export to excel/csv using Nested Repeaters. My project is web-based and i am using C#.Net. In this i use three repeaters. one displays ID, Name of the user. second...
3
by: Leon Mayne | last post by:
If I have a datatable which looks like this: Record Id, Group Id, Name 1, 1, Test 1 2, 1, Test 2 3, 2, Test 3 4, 3, Test 4 Is it possible to use nested repeaters to group the information by...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.