Reputation: 19
I am a beginner with asp.net I'm doing a image retrieval project , in the end i have images links now , i create image control, give it the link and add to the placeholder but it give me error : Object reference not set to an instance of an object
code :
System.Web.UI.WebControls.Image [] result = new System.Web.UI.WebControls.Image[links.Count()];
for (int h = 0; h < result.Length; h++)
{
result[h].ImageUrl = links[h]; /// here's the error
PlaceHolder1.Controls.AddAt(h, result[h]);
}
Upvotes: 2
Views: 387
Reputation: 14564
You need to instantiate the Image in each array index before assigning to a member in it. try:
result[h] = new Image() { ImageUrl = links[h] };
Upvotes: 3