I am attempting to Dynamically generate an HTML Table. What I am after is to have a header row and a second row of textboxes under the header row (all aligned horizontally across the page). I attempted this syntax - however it ignores the values that are selected in the checkboxlist, and the textboxes for input are stacked on top of each other instead of horizontal.
Can someone right the errors in my ways?
protected void btnBullDozer_Click(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder(string.Empty);
var columnname = string.Empty;
foreach (System.Web.UI.WebControls.ListItem item in checkboxtest.Items)
{
columnname = item.Text;
sb.Append("<table>");
sb.Append("<tr>");
sb.Append("<th>Sponsor Level</th>");
sb.Append("<th>" + item.Selected + "</th>");
}
sb.Append("</tr>");
var cm = string.Empty;
int z = 1;
foreach (System.Web.UI.WebControls.ListItem item in checkboxtest.Items)
{
cm = item.Text;
sb.Append("<tr>");
sb.Append("<td><input type=\"text\" name=\"field " + z + "\"></td>");
z = z + 1;
}
sb.Append("</tr>");
sb.Append("</table>");
mask.InnerHtml = sb.ToString();
}
Hypothetical of what my desired grid should look like - let's say that the user selected 4 options from the checkboxlist then I would want 5 headers (Sponsor Level, and the names selected) then one row with 5 empty textboxes underneath for the data entry