I have a data table with single column "ControlName" containing a list of different types of controls on a from. I used the following code to find the Control on the form.
DataTable dt = new DataTable();
dt.Columns.Add("ControlName", typeof(string));
dt.Load(dreader);
for (int i = 0; i < dt.Rows.Count; i++)
{
var myControlOnFormIs = this.Controls.Find(StringControlName, true);
for (int j = 0; j < dt.Rows.Count; j++)
{
// HERE WANT TO USE THE BELOW LINE TO ENABLE OR DISABLE THE CONTROL
this.Controls[myControlOnFormIs.ToString()].Enabled = false;
}
}As mentioned in the code, I want to find the CONTROL on the form and than enable/disable.
But I am getting the following error;
"Object reference not set to an instance of an object."
Please guide...