473,385 Members | 1,846 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,385 software developers and data experts.

Repeater ItemCreated vs ItemDataBound

Hi. Can anyone explain why, when setting the Text of a Label control in the ItemCreated event of a Repeater (example below), the Text value is NOT persisted to ViewState? I know this can be fixed by using the ItemDataBound event, but I don't understand why.

here's a page snippet:

<asp:Repeater runat="server" id="myRepeater"
OnItemCreated="myRepeater_ItemCreated">
...
<ItemTemplate><tr><td><asp:Label id="myLabel" runat="server" /></td></tr></ItemTemplate>
...
</asp:Repeater>

and here's a simple ItemCreated event:

protected void myRepeater_ItemCreated(object sender, RepeaterItemEventArgs
e)
{
foreach(Control ctrl in e.Item.Controls)
{
if(ctrl is Label)
{
DataRowView r=(DataRowView)e.Item.DataItem;
((Label)ctrl).Text=r["MY_FIELD"].ToString();
}
}
}

Thanks

KH
Nov 18 '05 #1
2 12306
Hi,

because in ItemCreated RepeaterItem is not yet added to Repeaters
Controls/Items collection, which means its child controls are neither.
Generally, Control lifecycle (Begin ViewState tracking is one phase in the
lifecycle) starts after Control is added to the Controls collection. So it
means state is tracked & saved for the changes made *after* control is added
to the Controls collection.

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke


"Kevin Hector" <an*******@discussions.microsoft.com> wrote in message
news:F6**********************************@microsof t.com...
Hi. Can anyone explain why, when setting the Text of a Label control in the
ItemCreated event of a Repeater (example below), the Text value is NOT
persisted to ViewState? I know this can be fixed by using the ItemDataBound
event, but I don't understand why.

here's a page snippet:

<asp:Repeater runat="server" id="myRepeater"
OnItemCreated="myRepeater_ItemCreated">
...
<ItemTemplate><tr><td><asp:Label id="myLabel" runat="server"
/></td></tr></ItemTemplate>
...
</asp:Repeater>

and here's a simple ItemCreated event:

protected void myRepeater_ItemCreated(object sender, RepeaterItemEventArgs
e)
{
foreach(Control ctrl in e.Item.Controls)
{
if(ctrl is Label)
{
DataRowView r=(DataRowView)e.Item.DataItem;
((Label)ctrl).Text=r["MY_FIELD"].ToString();
}
}
}

Thanks

KH

Nov 18 '05 #2
Hi,

because in ItemCreated RepeaterItem is not yet added to Repeaters
Controls/Items collection, which means its child controls are neither.
Generally, Control lifecycle (Begin ViewState tracking is one phase in the
lifecycle) starts after Control is added to the Controls collection. So it
means state is tracked & saved for the changes made *after* control is added
to the Controls collection.

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke


"Kevin Hector" <an*******@discussions.microsoft.com> wrote in message
news:F6**********************************@microsof t.com...
Hi. Can anyone explain why, when setting the Text of a Label control in the
ItemCreated event of a Repeater (example below), the Text value is NOT
persisted to ViewState? I know this can be fixed by using the ItemDataBound
event, but I don't understand why.

here's a page snippet:

<asp:Repeater runat="server" id="myRepeater"
OnItemCreated="myRepeater_ItemCreated">
...
<ItemTemplate><tr><td><asp:Label id="myLabel" runat="server"
/></td></tr></ItemTemplate>
...
</asp:Repeater>

and here's a simple ItemCreated event:

protected void myRepeater_ItemCreated(object sender, RepeaterItemEventArgs
e)
{
foreach(Control ctrl in e.Item.Controls)
{
if(ctrl is Label)
{
DataRowView r=(DataRowView)e.Item.DataItem;
((Label)ctrl).Text=r["MY_FIELD"].ToString();
}
}
}

Thanks

KH

Nov 18 '05 #3

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

Similar topics

1
by: Kevin Hector | last post by:
Hi. Can anyone explain why, when setting the Text of a Label control in the ItemCreated event of a Repeater (example below), the Text value is NOT persisted to ViewState? I know this can be fixed by...
1
by: slaforge | last post by:
I am trying use a repeater to process through the results of a sql query and produce a table that may or may not have multiple rows per record in the query, depending upon whether the technicians...
2
by: A Traveler | last post by:
Hi, I have a custom collection class i wrote, LineItemsCollection, which is a strongly typed collection of objects of my LineItem class. The LineItem class is a simple class with just a couple...
2
by: Mick | last post by:
Hi, just wanna know if it's possible to get access to my several label controls of my repeater's headertemplate in order to set their Text property ? Thks for help-
3
by: jason.gladstone | last post by:
Hello - I am trying to create a repeater control that contains a dropdownlist. A friend of mine sent me a sample in C#. I am trying to duplicate the sample in VB. This is the C# code in the...
2
by: Philippe Camus | last post by:
I didn't find any documentation about this behaviour. On postbacks the Repeater ItemCreated event is fired before Page_Load event It occurs for each item with empty...
1
by: RicercatoreSbadato | last post by:
I've put an ImageButton control in a repeater. I've set the 'OnItemBound' event of the repeater. Why when I click on the ImageButton it doesn't work? What else I have to do ?
5
by: Brad Baker | last post by:
I am trying to make a "tabbed" interface by iterating through a dataset with a conditional statement. For example: ...
2
by: =?Utf-8?B?Um9iZXJ0IFNtaXRo?= | last post by:
Hi I have a repeater control as shown below. The Itemtemplate contains a table with linkbuttons in each column of the row. However I wish to change the stlyle of the link button to...
12
by: =?Utf-8?B?Qi4gQ2hlcm5pY2s=?= | last post by:
I'm doing a web app in VB/Dot Net 2.0. I'm probably a bit rusty and I have no experience using the repeater control. I have a user control I've created with multiple properties. I've created a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.