0

I'm initializing a string and it's throwing a NullReferenceException:

string HTML = 
            "<div class=\"table-responsive formMOE\">" +
            "<table class=\"table\">" +
            "<thead class=\"white\"><tr><th>ID</th><th>Name</th><th>Type</th><th>Description</th><th>Ingredients</th><th>Price</th></tr></thead>" +
            "<tbody data-link=\"row\" class=\"rowlink\">" +
            "<tr>" +
            "<td><a href=\"Products.aspx?ProductID=" + product.ProductID + "\"></a>" + product.ProductID +
            "</td><td>" + product.Name +
            "</td><td>" + product.Type +
            "</td><td>" + product.Description +
            "</td><td>" + product.Ingredients +
            "</td><td>" + product.Price +
            " <span class=\"fa fa-shekel\"></span></td><td>" +
            "</td>" +
            "</tr>" +
            "</tbody></table></div>";

Even though I use this code:

string HTML =
        "<div class=\"table-responsive formMOE\">" +
        "<table class=\"table\">" +
        "<thead class=\"white\"><tr><th>Name</th><th>Description</th><th>Price</th></tr></thead>" +
        "<tbody data-link=\"row\" class=\"rowlink\">";

In another part and get no NullReferenceException.

I tried setting the string to a random value like "hi" and then setting it to the actual value I needed, didn't work.

Cœur
  • 32,421
  • 21
  • 173
  • 232
Mohanad
  • 107
  • 1
  • 1
  • 9

1 Answers1

2

The only problem I can see is that your product object is null.

The second one

string HTML =
"<div class=\"table-responsive formMOE\">" +
"<table class=\"table\">" +
"<thead class=\"white\"><tr><th>Name</th><th>Description</th><th>Price</th></tr></thead>" +
"<tbody data-link=\"row\" class=\"rowlink\">";

cannot generate a null exception.

Cœur
  • 32,421
  • 21
  • 173
  • 232
Razvan Dumitru
  • 8,710
  • 4
  • 29
  • 50