I have created the checkbox dynamically in C# with inside the <asp:ContentPlaceHolder>. I want that to be ordered in vertical and only one box will be checked at a time in code behind. Any solution?
Code:
DataTable table = new DataTable();
table.Columns.Add("Betoption", typeof(string));
table.Columns.Add("id", typeof(string));
table.Rows.Add("Main", "1");
table.Rows.Add("Corner", "2");
table.Rows.Add( "Card & Foul", "3");
table.Rows.Add( "Under / Over", "4");
table.Rows.Add( "Dilantin", "5");
table.Rows.Add( "Home / Away", "6");
table.Rows.Add("First Half", "7");
DataRow[] exemption = table.Select();
foreach (DataRow dr in exemption)
{
string option = dr["Betoption"].ToString();
string optionID = dr["id"].ToString();
var chk = new CheckBox { ID = optionID, Text = option, CssClass = "name", AutoPostBack = true };
PlaceHolder1.Controls.Add(chk);
}
Instead of
Checkboxyou can useCheckBoxListand set value ofRepeatDirectionProperty as shown below:And if you want only one item to be checked at a time, I would suggest to use
RadioButtonListinstead of Checkbox list.In above code, Just replace
CheckBoxList()withRadioButtonList()