Reputation: 5930
I have a button in repeater and I want to loop in data items of repeater in this button click event. Here is my code:
protected void btnPromotionButton_OnClick(object sender, EventArgs e)
{
try
{
foreach (RepeaterItem item in rptPromotionProducts.Items)
{
if (item.DataItem == null)
{
continue;
}...
And here is my repeater:
<asp:Repeater ID="rptPromotionProducts" runat="server" OnItemDataBound="rptPromotionProducts_OnItemDataBound">
<ItemTemplate>
<li>
<asp:HyperLink runat="server" ID="hlProduct" CssClass="product_image">
<asp:Image runat="server" ID="imgWindow" />
</asp:HyperLink>
<div class="product_info">
<h3>
<a href="#">
<%# Eval("Name") %></a></h3>
</div>
<div>
<asp:Button ID="btnPromotionButton" runat="server" Text="Sepete Ekle" OnClick="btnPromotionButton_OnClick" />
</div>
</div>
</li>
</ItemTemplate>
</asp:Repeater>
item.DataItem is always comes null however repeater has rows. Is that possible to loop after page post and back?
Upvotes: 3
Views: 5693
Reputation: 1908
Similar questions was already answered here and here.
The short answer for this question is NO. You cannot access the DataItem after postback.
Alternatives to retrieve your data would be use a Hidden Field, a DataSource linked to your Repeater or a session object containing the data.
Upvotes: 3