First, here is the code.
DataRow[] exemption = ds.Tables[2].Select("ValidExemptionTypeID='2'");
foreach (DataRow dr in exemption)
{
string exemptionType = dr["ValidExemptionTypeID"].ToString();
string exemptionID = dr["ValidExemptionID"].ToString();
string exemptionDesc = dr["validExemptionDescription"].ToString();
string displayLabel = dr["DisplayLabel"].ToString();
sb.Append("<table><tr><td colspan='3'> <br /></td></tr></table>");
sb.Append("<table align='center' width='730px'>");
sb.Append("<tr><td width='20px' align='left'><input type=\"checkbox\" ID=\"chk" + exemptionID + "\" runat=\"server\" /></td>");
sb.Append("<td align='left'><strong>" + exemptionDesc + "</strong></td>");
sb.Append("</table>");
sb.Append("<table align='center' width='630px'>");
sb.Append("<tr><td>" + displayLabel + "</td></tr>");
sb.Append("<tr><td colspan='2'> </td></tr>");
sb.Append("</table>");
sb.Append("<table style='border: 1px solid gray' align='center' width='700px'>");
sb.Append("<tr><td colspan='3'><strong>Select Exeption Reason</strong></td></tr>");
sb.Append("<tr><td><input type=\"checkbox\" ID=\"chkLocal" + exemptionID + "\" runat=\"server\" /></td>");
sb.Append("<td align='left'><strong>Local Restriction</strong></td>");
sb.Append("<td align='left'><i>NOTE: Please limit explanation to xx characters or less</i></td>");
sb.Append("</tr><tr>");
sb.Append("<td valign='top'><input type=\"checkbox\" ID=\"chkOther" + exemptionID + "\" runat=\"server\" /></td>");
sb.Append("<td valign='top' align='left'><strong>Other (Please Specify to the right)</strong></td>");
sb.Append("<td colspan=><textarea style='width: 390px; max-width: 390px;' id=\"txtOther" + exemptionID + " cols=\"100\" rows=\"2\" wrap=\"virtual\" runat=\"server\"></textarea></td>");
sb.Append("</tr>");
sb.Append("</table>");
sb.Append("<table><tr><td colspan='3'> <br /></td></tr></table>");
count++;
}
return sb.ToString();
}
This goes through a datarow array with 14 rows and creates a checkbox for each one, then adds two checkboxes for each row for local and other exemptions. What I just cannot figure out is how to check the boxes in the codebehind to make sure they're checked. Any suggestions or links to help would be greatly appreciated.
You have to change a few things. The big problem is you can't use server tags as a string. So the runat server in your checkboxes isn't doing anything. if you look at the generated html, you will see runat="server" is in the HTML.
so, if you want to take this approach, which is fine, then give the checkboxes a unique name like name=\"chkOther_dr1\" then you can use Request.Form or Request.Params to check to see if the boxes are checked, they will not be part of the collection if they aren't checked.
Even if you actually create the server controls you will have the same problem because they will not exist when you try to check them in your postback. so...
DataRow[] exemption = ds.Tables[2].Select("ValidExemptionTypeID='2'");
foreach (DataRow dr in exemption)
{
string exemptionType = dr["ValidExemptionTypeID"].ToString();
string exemptionID = dr["ValidExemptionID"].ToString();
string exemptionDesc = dr["validExemptionDescription"].ToString();
string displayLabel = dr["DisplayLabel"].ToString();
sb.Append("<table><tr><td colspan='3'> <br /></td></tr></table>");
sb.Append("<table align='center' width='730px'>");
sb.Append("<tr><td width='20px' align='left'><input type=\"checkbox\" name=\"chk" + exemptionID + "\" /></td>");
sb.Append("<td align='left'><strong>" + exemptionDesc + "</strong></td>");
sb.Append("</table>");
sb.Append("<table align='center' width='630px'>");
sb.Append("<tr><td>" + displayLabel + "</td></tr>");
sb.Append("<tr><td colspan='2'> </td></tr>");
sb.Append("</table>");
sb.Append("<table style='border: 1px solid gray' align='center' width='700px'>");
sb.Append("<tr><td colspan='3'><strong>Select Exeption Reason</strong></td></tr>");
sb.Append("<tr><td><input type=\"checkbox\" name=\"chkLocal_" + exemptionID + "\" /></td>");
sb.Append("<td align='left'><strong>Local Restriction</strong></td>");
sb.Append("<td align='left'><i>NOTE: Please limit explanation to xx characters or less</i></td>");
sb.Append("</tr><tr>");
sb.Append("<td valign='top'><input type=\"checkbox\" name=\"chkOther_" + exemptionID + "\" /></td>");
sb.Append("<td valign='top' align='left'><strong>Other (Please Specify to the right)</strong></td>");
sb.Append("<td colspan=><textarea style='width: 390px; max-width: 390px;' name=\"txtOther_" + exemptionID + " cols=\"100\" rows=\"2\" wrap=\"virtual\" ></textarea></td>");
sb.Append("</tr>");
sb.Append("</table>");
sb.Append("<table><tr><td colspan='3'> <br /></td></tr></table>");
count++;
}
return sb.ToString();
and then to get them use the params / form collection on Request and look for the part before the underscore (use StartsWith).