Search code examples
asp.netc#-4.0radio-buttoncode-behindradiobuttonlist

how to add space between radiobuttonlist which is created dynamically in code behind


Im creating radiobuttonlist accordingly. I want space in between them. All are done in code behind.

                RadioButtonList ddlst1 = new RadioButtonList();
                for (int k = 1; k < 5; k++)
                {

                    ddlst1.Items.Add(k.ToString());


                }                                  
                ddlst1.SelectedValue = i < choice1.Count() ? choice1[i] : string.Empty;
                ddlst1.RepeatDirection = RepeatDirection.Horizontal;
                ddlst1.AutoPostBack = false;      

Solution

  • You can also use cellpadding and cell spacing(But its at design time)

    <asp:RadioButtonList ID="ddlst1" runat="server" CellPadding="3" CellSpacing="2">
    

    If you want to give at code behind then follow above answer i.e..ddlst1.Items[k].Attributes.CssStyle.Add("margin-right:5px;")