Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在ASP.NET RadioButtonList中的项目之间添加空格_Asp.net_Formatting_Markup_Radiobuttonlist - Fatal编程技术网

如何在ASP.NET RadioButtonList中的项目之间添加空格

如何在ASP.NET RadioButtonList中的项目之间添加空格,asp.net,formatting,markup,radiobuttonlist,Asp.net,Formatting,Markup,Radiobuttonlist,我有一个ASP.NET RadioButton列表,它使用RepeatDirection=“Horizontal”将四个项目显示在一行中。我使用RepeatLayout=“Flow”来避免表的标记。但是,这会导致列表中的项目彼此相邻,这看起来不太好 因此,我尝试使用表布局来利用cellspacting和/或CellPadding属性。不幸的是,这些属性会影响表中的垂直和水平间距/填充,因此在获得水平间距的同时,也会获得不需要的垂直间距 在这一点上,我要说的是: <asp:RadioButt

我有一个ASP.NET RadioButton列表,它使用RepeatDirection=“Horizontal”将四个项目显示在一行中。我使用RepeatLayout=“Flow”来避免表的标记。但是,这会导致列表中的项目彼此相邻,这看起来不太好

因此,我尝试使用表布局来利用cellspacting和/或CellPadding属性。不幸的是,这些属性会影响表中的垂直和水平间距/填充,因此在获得水平间距的同时,也会获得不需要的垂直间距

在这一点上,我要说的是:

<asp:RadioButtonList ID="rblMyRadioButtonList" runat="server" 
    RepeatDirection="Horizontal"
    RepeatLayout="Flow" >
    <asp:ListItem Selected="false" Text="Item One&nbsp;&nbsp;&nbsp;&nbsp;" Value="Item_1" />
    <asp:ListItem Selected="false" Text="Item Two&nbsp;&nbsp;&nbsp;&nbsp;" Value="Item_2" />
    <asp:ListItem Selected="false" Text="Item Three&nbsp;&nbsp;&nbsp;&nbsp;" Value="Item_3" />
    <asp:ListItem Selected="false" Text="Item Four&nbsp;&nbsp;&nbsp;&nbsp;" Value="Item_4" />
</asp:RadioButtonList>

…对我大喊大叫“你做得不对!”


实现这一点的正确方法是什么?

使用css为这些特定元素添加右边距。通常,我会构建控件,然后运行它以查看生成的html结构是什么样的,然后让css仅更改这些元素

最好通过设置类来实现这一点。将
CssClass=“myrblclass”
属性添加到列表声明中

您还可以通过编程方式将属性添加到项目中,这将从另一面显示出来

rblMyRadioButtonList.Items[x].Attributes.CssStyle.Add("margin-right:5px;")

这可能对您更有利,因为您可以为除最后一个之外的所有对象添加该属性。

我知道这是一个老问题,但我这样做了:

<asp:RadioButtonList runat="server" ID="myrbl" RepeatDirection="Horizontal" CssClass="rbl"> 

如果“重复布局”为“表格”,则还可以使用“单元间距”和“单元填充”属性

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

更简单

ASP.NET

<asp:RadioButtonList runat="server" ID="MyRadioButtonList" RepeatDirection="Horizontal" CssClass="FormatRadioButtonList"> ...

尽管如此,针对这种情况的最佳方法是设置自定义CSS样式-另一种方法可以是:

  • 使用
    Width
    属性,并根据您认为更适合您的目的设置百分比
在我想要的场景中,我需要设置(2)个单选按钮/项目,如下所示:

o项目1 o项目2
在前三个元素的结束标记之前添加style=“margin right:30px”就成功了。一旦你看到它,就很明显了。:-)我想应该是:rblMyRadioButtonList.Items[x].Attributes.CssStyle.Add(“右边距”,“5px”),我会解释他必须为列表中的每一项添加这些内容。Russell已经提供了这个答案。在回答问题时,请坚持提供新的解决方案。嘿,泰勒,别再摆出你的精英架子了。通过计票证明,鲁本的答案更好/更有效;)这正是我所需要的。
<asp:RadioButtonList runat="server" ID="MyRadioButtonList" RepeatDirection="Horizontal" CssClass="FormatRadioButtonList"> ...
.FormatRadioButtonList label
{
  margin-right: 15px;
}
<asp:RadioButtonList ID="rbn" runat="server" RepeatLayout="Table" RepeatColumns="2"
                        Width="100%" >
                        <asp:ListItem Text="1"></asp:ListItem>
                        <asp:ListItem Text="2"></asp:ListItem>
                        <asp:ListItem Text="3"></asp:ListItem>
                        <asp:ListItem Text="4"></asp:ListItem>
                    </asp:RadioButtonList>