So here's the scenario: I have a table that is already filled with data, and I want to add checkboxes and textboxes into it. Check out the code snippet below:
int count1 = 0;
TableCell tc;
foreach (TableRow tr in Resource_TBL.Rows)
{
tr.Cells.Add(tc = new TableCell());
CheckBox cbox = new CheckBox();
cbox.ID = ""+count1;
cbox.Attributes.Add("onclick", "document.getElementById('textbox_" + count1 + "').disabled=this.checked;");
tc.Controls.Add(cbox);
tr.Cells.Add(tc = new TableCell());
TextBox tbox = new TextBox();
tbox.ID = "textbox_" + count1;
tbox.CssClass = "form-control";
tbox.Enabled = false;
tbox.Attributes.Add("placeholder", "Enter Detail Here");
count1 += 1;
tc.Controls.Add(tbox);
}
I attempted this as well:
cbox.Attributes.Add("onclick", "document.getElementById('textbox_" + count1 + "').Enabled=this.checked;");
Unfortunately, it didn't work and threw an error stating (Unable to set property 'Enabled' of undefined or null reference).
Does anyone know of another approach to achieve this functionality?