0

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  class="table table-responsive">
                                    <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 class="cart_product_img">
                                                        <img src='<%#"../../../Images/Shoping/"+ Eval("Image") %>' />

                                                    </td>

                                                    <td class="price">
                                                        <asp:ImageButton ID="btninImage" OnClick="PinImage_Click" CommandName="PinImage" ImageUrl="~/img/web/pinn.png" runat="server" />
                                                    </td>
                                                    <td class="qty">
                                                        <div class="qty-btn d-flex">
                                                            <div class="quantity">
                                                                <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

        }
4
  • You have a typo : control lblProId vs .Item.FindControl("blProId") Commented Jun 8, 2022 at 23:50
  • sorry it was mistake while coping the code Commented Jun 9, 2022 at 0:03
  • Has your DtImages Repeater added data to the DataSource? Commented Jun 9, 2022 at 0:21
  • Set a break point and inspect the controls collection n e.Item Commented Jun 9, 2022 at 2:44

1 Answer 1

1

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");                
        }
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.