0

I'm building an exemption request form that populates from an SQL Server 2008 database.

DataRow[] exemption = ds.Tables[2].Select();
    foreach (DataRow dr in exemption)
    {
        string exemptionType = dr["ExemptionType"].ToString();
        string exemptionID = dr["ExemptionID"].ToString();
        string exemptionDesc = dr["ExemptionDescription"].ToString();
        string displayLabel = dr["DisplayLabel"].ToString();
        sb.Append("<table align='center' width='730px'>");
        sb.Append("<tr><td><asp:CheckBox ID=\"chk" + exemptionID + "\" runat=\"server\" /></td>");
        sb.Append("<td><strong>" + exemptionDesc + "</strong></td>");
        sb.Append("</table>");
        sb.Append("<table align='center' width='630px'>");
        sb.Append("<tr><td>" + displayLabel + "</td></tr>");
        sb.Append("</table>");
    }
    return sb.ToString();

As it stands right now, the table builds fine, all the data displays fine, but the checkbox does not show up. Was wondering if doing it this way is possible at all, and if so, what am I doing wrong?

0

1 Answer 1

2

You're inserting ASP.NET into your HTML and that HTML is probably not getting processed by ASP.NET. If you want to do it the way you're doing it now... switch to using input tags like so...

DataRow[] exemption = ds.Tables[2].Select(); 
foreach (DataRow dr in exemption) 
{ 
  string exemptionType = dr["ExemptionType"].ToString(); 
  string exemptionID = dr["ExemptionID"].ToString(); 
  string exemptionDesc = dr["ExemptionDescription"].ToString(); 
  string displayLabel = dr["DisplayLabel"].ToString(); 
  sb.Append("<table align='center' width='730px'>"); 
  sb.Append("<tr><td><input type=\"checkbox\" id=\"chk" + exemptionID + "\" /></td>"); 
  sb.Append("<td><strong>" + exemptionDesc + "</strong></td>"); 
  sb.Append("</table>"); 
  sb.Append("<table align='center' width='630px'>"); 
  sb.Append("<tr><td>" + displayLabel + "</td></tr>"); 
  sb.Append("</table>"); 
} 
return sb.ToString(); 

The other route would be to actually create the ASP.NET Checkboxes. That would look somethig like this...

  var checkbox = new CheckBox();
  checkbox.ID = "chk" + exemptionId;
  wrapper.Controls.Add(checkbox);

Where wrapper is a Panel or something of the sort.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.