You need to create an Adapter for this. First, add the following code to your project somewhere.
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.Adapters;
public class CheckBoxListAdapter : WebControlAdapter
{
protected override void Render(HtmlTextWriter writer)
{
var targetControl = (CheckBoxList)Control;
int itemCounter = 0;
if (targetControl == null)
{
base.Render(writer);
return;
}
writer.Indent++;
foreach (ListItem item in targetControl.Items)
{
var inputId = targetControl.ClientID + "_" + itemCounter++;
//label
writer.AddAttribute("class", "container");
writer.RenderBeginTag("label");
writer.Write(item.Text);
//input
writer.AddAttribute("type", "checkbox");
writer.AddAttribute("value", item.Value);
writer.AddAttribute("name", targetControl.UniqueID + "$" + (itemCounter - 1));
writer.AddAttribute("id", inputId);
if (item.Selected)
{
writer.AddAttribute("checked", "checked");
}
if (!targetControl.Enabled || !item.Enabled)
{
writer.AddAttribute("disabled", "disabled");
}
writer.RenderBeginTag("input");
writer.RenderEndTag();
//span label
writer.AddAttribute("class", "checkmark");
writer.RenderBeginTag("span");
writer.RenderEndTag();
//end label
writer.RenderEndTag();
//horizontaal of verticaal
if (targetControl.RepeatDirection == RepeatDirection.Vertical)
{
writer.Write("<br />");
}
//register item for postback
Page.ClientScript.RegisterForEventValidation(targetControl.UniqueID, item.Value);
}
writer.Indent--;
//register for postback
Page.ClientScript.RegisterForEventValidation(targetControl.UniqueID);
}
}
Then add a "ASP.Net folder" by right clicking on your project you will find under "Add" > "Add ASP.Net folder". There add a "App_browser" folder.
In that created folder add a "BrowserFile.browser" file. Put the following code in there
<browsers>
<browser refID="Default">
<controlAdapters>
<adapter controlType="System.Web.UI.WebControls.CheckBoxList" adapterType="TestOmgeving.CheckBoxListAdapter" />
</controlAdapters>
</browser>
</browsers>
Now a CheckBox will render as
<label class="container">This is the label
<input type="checkbox" value="val" name="ctl00$mainContentPane$CheckBoxList1$1" id="mainContentPane_CheckBoxList1_1">
<span class="checkmark"></span>
</label>