Say I have the below HTML that I want to generate from the code behind in a C# WebForms application. How do I create the label for the checkbox?
HTML
<div class="col-lg-8 col-lg-offset-1">
<input id="combo" type="checkbox" value="false" />
<label for="combo" class="margin">Text Here</label>
</div>
Code behind
private static HtmlGenericControl CreateHtmlInputCheckBoxControl(Filters filter)
{
HtmlGenericControl column = CreateColumn(filter);
column.Controls.Add(new HtmlInputCheckBox { Checked = false, Value = filter.Caption });
return column;
}
private static HtmlGenericControl CreateColumn(Filters filter, string additionalClasses = "")
{
HtmlGenericControl div = new HtmlGenericControl("div");
div.Attributes["class"] = string.Format("col-lg-{0} col-lg-offset-{1} {2}", filter.ColumnSpan, filter.ColumnOffset, additionalClasses);
return div;
}
Is adding a label for possible in this method or is using a literal the only way to accomplish this?