I want to change the property of an existing CheckBox
object in my code:
string checkBoxName = "checkBox" + Convert.ToString(index);
Object objCheckBox = checkBoxName;
CheckBox myCheckBox = objCheckBox as CheckBox;
if (words[1] == "-1")
{
myCheckBox.Checked = false;
}
else
{
myCheckBox.Checked = true;
}
The code snippet above did not cause a compile error but caused a runtime error as
Object reference not set to an instance of an object.
What should I do?