G
Guest
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
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