In my application reading value from front end into label lbBillableAmount1 but somehow null value is passed to it and code block terminates and transfers to catch block.Please refer below code:
protected void RPClientWish_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
try
{
if(Convert.ToInt32(Session["RoleId"])==1)
{
Label lb2 = (Label)e.Item.FindControl("lb2");
lb2.Visible = true;
Label lbBillableAmount1 = (Label)e.Item.FindControl("Label7");
lbBillableAmount1.Visible = true;
}
}
catch (Exception ex)
{
ex.Message.ToString();
}
}
Please let me know solution for this because even after dropping label and creating new one still getting error. Error is :Object reference not set to an instance of object. I have read lot of posts for this error but nothing is solving the issue.
Here is my repeater code:
<asp:Repeater ID="RPClientWish" runat="server" OnItemDataBound="RPClientWish_ItemDataBound" >
<HeaderTemplate>
<div class="col-md-12">
<div class="EmployeeList">
<div class="col-md-3">
<asp:Label ID="lbname" runat="server" Font-Bold="true" Text="Name" style="font-family:'Segoe UI';"></asp:Label>
</div>
<div class="col-md-1"> </div>
<div class="col-md-1"> </div>
<div class="col-md-2"><asp:Label ID="Label2" runat="server" Font-Bold="true" Text="Hours" style="font-family:'Segoe UI';"></asp:Label></div>
<div class="col-md-1"> </div>
<div class="col-md-2"><asp:Label ID="lb1" runat="server" Font-Bold="true" Text="Billable Hours" style="font-family:'Segoe UI';"></asp:Label></div>
<div class="col-md-2">
<asp:Label ID="lb2" runat="server" Font-Bold="true" Text="Billable Amount" style="font-family:'Segoe UI';" Visible="false"></asp:Label>
</div>
</div>
</div>
</HeaderTemplate>
<ItemTemplate>
<div class="col-md-12">
<div class="EmployeeList">
<div class="col-md-3">
<asp:Label ID="lbClientname" runat="server" Font-Bold="true" Text='<%# Eval("ClientName")%>' style="font-family:'Segoe UI';"></asp:Label>
</div>
<div class="col-md-1"> </div>
<div class="col-md-1"> </div>
<div class="col-md-2"><asp:Label ID="lbhours" runat="server" Font-Bold="true" Text='<%# Eval("TotalHours")%>' style="font-family:'Segoe UI';"></asp:Label></div>
<div class="col-md-1"> </div>
<div class="col-md-2"><asp:Label ID="lbBillableHours1" runat="server" Font-Bold="true" Text="00" style="font-family:'Segoe UI';" ></asp:Label></div>
<div class="col-md-2">
**<asp:Label ID="Label7" runat="server" Text="Label"></asp:Label>
</div>**
</div>
<div class="col-md-12"><hr /></div>
</div>
</ItemTemplate>
</asp:Repeater>