I have a repeater inside the HTML table the problem is I'm trying to get label value on item date bound event but it always returns null I tried to use the same code without the HTML table its working fine so is there a way to get value while I'm using an HTML table
<table >
<asp:Repeater ID="DtImages" OnItemDataBound="DtImages_ItemDataBound" runat="server">
<HeaderTemplate>
<thead>
<tr>
<th>Image</th>
<th>update</th>
</tr>
</thead>
</HeaderTemplate>
<ItemTemplate>
<tbody>
<tr>
<td >
<img src='<%#"../../../Images/Shoping/" Eval("Image") %>' />
</td>
<td >
<asp:ImageButton ID="btninImage" OnClick="PinImage_Click" CommandName="PinImage" ImageUrl="~/img/web/pinn.png" runat="server" />
</td>
<td >
<div >
<div >
<asp:ImageButton ID="UpdateImg" OnClick="UpdateImg_Click" CommandName="UpdateImage" ImageUrl="~/img/web/upload.png" runat="server" />
<asp:Label ID="lblProId" runat="server" Text='<%# Eval("ProID") %>' ></asp:Label>
</div>
</div>
</td>
</tr>
</tbody>
</ItemTemplate>
</asp:Repeater>
</table>
code behind
protected void DtImages_ItemDataBound(object sender,RepeaterItemEventArgs e)
{
Label Pinned =(Label) e.Item.FindControl("lblProId") ;// its return null
// some codes
}
CodePudding user response:
When the repeater data bind triggers, headers, alternating rows, and a data row all are feed to that routine.
So, you have to do this:
protected void DtImages_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if ((e.Item.ItemType == ListItemType.Item) |
(e.Item.ItemType == ListItemType.AlternatingItem))
{
Label Pinned = (Label)e.Item.FindControl("lblProId");
}
}