I have a GridView populated with SQL data. If the account has not been provisioned, a dynamically created checkbox is created in the 6th column to allow for provisioning according to my company's guidlines. I need to check the checkbox in each record to see if it checked or not, but I cannot get the following code to work on my button click. The 6th column (which was manually added via edit columns and is no data bound) holds the dynamically created check box, but it never evaluates to true.
foreach (GridViewRow gv in GridView1.Rows)
{
int index = gv.RowIndex;
//Get Value
string id = "MainContent_GridView1_ctl00_" + index;
CheckBox chk = GridView1.Rows[index].Cells[6].FindControl(id) as CheckBox;
//System.Windows.Forms.MessageBox.Show(chk.ToString());
if (chk == null) { System.Windows.Forms.MessageBox.Show(id + " " + "is NOT checked"); }
if (chk != null && chk.Checked)
{
System.Windows.Forms.MessageBox.Show(id + " " + "is checked");
}
}
Here is the page source after runtime
<div>
<table cellspacing="0" align="Center" rules="all" border="1" id="MainContent_GridView1" style="width:800px;border-collapse:collapse;">
<tr>
<th align="left" scope="col">Employee Number</th><th align="left" scope="col">First Name</th><th align="left" scope="col">Last Name</th><th align="left" scope="col">License Code</th><th align="left" scope="col">Job Title</th><th scope="col">Provisioned</th><th scope="col">Process</th>
</tr><tr>
<td>123123</td><td>Pete</td><td>Griffin</td><td> </td><td>Test Record</td><td align="center">False</td><td align="center"><input id="MainContent_GridView1_ctl00_0" type="checkbox" name="ctl00$MainContent$GridView1$ctl02$ctl00" checked="checked" /></td>
</tr>
</table>
</div>
I have been all over the web. I am a moderate C# programmer, but no pro by any means.