C#.Net: Create CheckBoxList Dynamically (In Runtime)

This is how you can create CheckBoxList in run time in C#.Net.

aspx Code:

<asp:Panel ID="PnlControl" runat="server"> </asp:Panel>

C# Code:

CheckBoxList cd = new CheckBoxList();
cd.CssClass = "llcDynamicCheckbox";
cd.ID = "llcDynamicCheckbox";
cd.Font.Size = 8;
for (int i = 0; i < 5; i++)
{
  ListItem lt = new ListItem();
  lt.Text = "Checkbox " + i.ToString();
  lt.Value =
i.ToString();
  cd.Items.Insert(i, lt);
}
PnlControl.Controls.Add(cd);

Accordingly you can modify this code.

 
Designed and Maintained by