Nilesh Patil

Nilesh Patil

  • NA
  • 3k
  • 115.6k

threw an exception of type system nullreferenceexception c#

Nov 17 2017 12:01 AM
Hello,
 
I am use repeater control and i that i have a label so i am assign value to this label in code behind but system gives error threw an exception of type system nullreferenceexception c#
 
This is my aspx code
  1. <asp:Repeater ID="Repeater1" runat="server">  
  2. <HeaderTemplate>  
  3. <table>  
  4. </HeaderTemplate>  
  5. <ItemTemplate>  
  6. <tr>  
  7. <td>  
  8. <asp:Label ID="lbldata" runat="server"></asp:Label>  
  9. </td>  
  10. </tr>  
  11. </ItemTemplate>  
  12. <FooterTemplate>  
  13. </table>  
  14. </FooterTemplate>  
  15. </asp:Repeater>  
And this is Code behind:-
  1. DataTable dt_OwnerFilter = new DataTable();  
  2. Label r1 = (Label)Page.FindControl("lbldata");  
  3. dt_OwnerFilter = bl.BL_FetchOwnerInfo(bo);  
  4. pgsource.DataSource = dt_OwnerFilter.DefaultView;  
  5. lblfetchdata.Text = string.Empty;  
  6. int i = 1;  
  7. foreach (DataRow dRow in dt_OwnerFilter.Rows)  
  8. {  
  9. if (dt_OwnerFilter.Rows.Count > 0)  
  10. {  
  11. string htmlcode = "";  
  12. htmlcode = "<a class='btn btn-primary' onclick='fnShow(" + dRow["PropertyDetailsId"] + ")'> " + i + "</a>";  
  13. r1.Text += htmlcode + "<br>"//// Here is error  
  14. }  
  15. i = i + 1;  
  16. }

Answers (3)