I have this detailsview in which I have a field and an imagebutton. If the value of the field is empty i'd like to set the imagebutton invisible and if it's not empty I'd like to see the imagebutton.
Here's my code:
//for (int i = 0; i < DetailsView1.Fields.Count; i++)
//{
Label lbl1 = (Label)DetailsView1.FindControl("Label1");
ImageButton img = (ImageButton)DetailsView1.FindControl("ImageButton1");
if (lbl1 != null)
{
LabelABC.Text = lbl1.Text.ToString();
img.Visible = true;
}
else
{
img.Visible = false;
}
//}
I'm not sure if the for loop is needed here. I also tried working with .Rows[5].Cells[1].Find...
but I get an out of range error then.
With the code I posted above the error I get says:
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
at the line: img.Visible = false;
Any tips on how to solve this please? Thank you for your time.