I am trying to hide a label inside a repeater.

 <td >
            <div >
  <asp:Repeater ID="rpt1" runat="server" OnItemDataBound="rpt1_ItemDataBound">
                    <HeaderTemplate>
                        <table >
                            <tr>
                                <td >
                                    <div >
                                        <label id="lbl1"  runat="server">
                                            <b>Project</b>
                                        </label>
                                    </div>
                                </td>
                            </tr>
                       </table>
                    </HeaderTemplate>
                </asp:Repeater>
            </div>
        </td>

I want to hide Label lbl1 dynamically.

protected void rpt1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Header)
        {
            //IT COMES HERE
            Label label = e.Item.FindControl("lbl1") as Label;
            label.Visible = false;
            // ERROR: OBJECT REFERENCE NOT SET TO AN INSTANCE OF AN OBJ
        }
    }

Here, when I try to debug the code, it comes inside the loop but gives me object reference not set to an instance of an object error.

Related posts

Recent Viewed