If you ever used the ItemDataBound event in a Repeater you are probebly aware of the fact that RepeaterItemEventArgs.Item.DataItem is null after a postback if you only bind your Repeater if !Page.IsPostBack.
If you need to access some of the data but find yourself with a null object, you can use this little workaround.
Add a control to your ItemTemplate. A Label will work just fine.
<ItemTemplate>
<tr>
<td><asp:Label ID="GroupLabel" Text='<%# Eval("Key") %>' runat=server></asp:Label></td>
</tr>
</ItemTemplate>
In your event use Label GroupLabel = e.Item.FindControl("GroupLabel") as Label;
And access the Text property of the Label.
Posted
10 May 2009 10:35 AM
by
Gal Ratner