T
Thomas Nielsen [AM Production A/S]
Hi,
Whenever i bind data to a repeater, i use the repeater ItemCreated event to
be able to properly format the data from the datasource into the repeater.
Example, codefront:
<asp:Repeater id="myRepeater" Runat="server" EnableViewState=True>
<ItemTemplate>
<tr>
<td class="listCell"><asp:Literal Runat=server
ID="ReferenceData"></asp:Literal></td>
</tr>
</ItemTemplate>
</asp:Repeater>
Example, codebehind:
public void RecordList_ItemCreated(object myObject, RepeaterItemEventArgs
args)
{
myString =
((string)((DataRowView)args.Item.DataItem)["ReferenceData"]).ToString();
((Literal)args.Item.FindControl("ReferenceData")).Text = myString;
}
This allows me to format the data from the datasource in any way i prefer,
which i like.
However, it looks like the properties i set in the codebehind are not stored
in the ViewState, meaning that these are not preserved at postback. If i
enable ViewState on the repeater, structure and objects of the repeater are
preserved fine on postback, but in this example, Reference does not contain
the .text i originally set in the RecordList_ItemCreated event.
Is there a way to preserve these values in the ViewState?. I would also
appreciate any advice on best pactices in this scenario; I've seen examples
where the data is re-bound on postback, which i really cannot accept due to
performance issues.
Cheers,
/Thomas
Whenever i bind data to a repeater, i use the repeater ItemCreated event to
be able to properly format the data from the datasource into the repeater.
Example, codefront:
<asp:Repeater id="myRepeater" Runat="server" EnableViewState=True>
<ItemTemplate>
<tr>
<td class="listCell"><asp:Literal Runat=server
ID="ReferenceData"></asp:Literal></td>
</tr>
</ItemTemplate>
</asp:Repeater>
Example, codebehind:
public void RecordList_ItemCreated(object myObject, RepeaterItemEventArgs
args)
{
myString =
((string)((DataRowView)args.Item.DataItem)["ReferenceData"]).ToString();
((Literal)args.Item.FindControl("ReferenceData")).Text = myString;
}
This allows me to format the data from the datasource in any way i prefer,
which i like.
However, it looks like the properties i set in the codebehind are not stored
in the ViewState, meaning that these are not preserved at postback. If i
enable ViewState on the repeater, structure and objects of the repeater are
preserved fine on postback, but in this example, Reference does not contain
the .text i originally set in the RecordList_ItemCreated event.
Is there a way to preserve these values in the ViewState?. I would also
appreciate any advice on best pactices in this scenario; I've seen examples
where the data is re-bound on postback, which i really cannot accept due to
performance issues.
Cheers,
/Thomas