如何在 ASP.NET RadioButtonList 中的项目之间添加空格
我有一个 ASP.NET RadioButtonList,它使用 RepeatDirection="Horizontal" 将四个项目显示在一行上。我使用 RepeatLayout="Flow" 来避免表格标记。但是,这会导致列表中的项目彼此相邻放置,这看起来不太好。
因此,我尝试使用表格布局来利用 CellSpacing 和/或 CellPadding 属性。不幸的是,这些属性会影响表格内的垂直和水平间距/填充,因此当我得到水平间距时,我也会得到不需要的垂直间距。
在这一点上,我想说的是:
<asp:RadioButtonList ID="rblMyRadioButtonList" runat="server"
RepeatDirection="Horizontal"
RepeatLayout="Flow" >
<asp:ListItem Selected="false" Text="Item One " Value="Item_1" />
<asp:ListItem Selected="false" Text="Item Two " Value="Item_2" />
<asp:ListItem Selected="false" Text="Item Three " Value="Item_3" />
<asp:ListItem Selected="false" Text="Item Four " Value="Item_4" />
</asp:RadioButtonList>
……这对我尖叫“你做得不对!”
实现这一目标的正确方法是什么?
I've got an ASP.NET RadioButtonList that displays four items using RepeatDirection="Horizontal" to display them on a single line. I'm using RepeatLayout="Flow" to avoid the markup for a table. However, this causes the items in the list to be placed right next to each other, which does not look good.
So, I tried the table layout to take advantage of the CellSpacing and/or CellPadding properties. Unfortunately, these properties affect both the vertical and horizontal spacing/padding within the table, so while I get the horizontal spacing, I also get undesired vertical spacing.
At this point, I'm down to this:
<asp:RadioButtonList ID="rblMyRadioButtonList" runat="server"
RepeatDirection="Horizontal"
RepeatLayout="Flow" >
<asp:ListItem Selected="false" Text="Item One " Value="Item_1" />
<asp:ListItem Selected="false" Text="Item Two " Value="Item_2" />
<asp:ListItem Selected="false" Text="Item Three " Value="Item_3" />
<asp:ListItem Selected="false" Text="Item Four " Value="Item_4" />
</asp:RadioButtonList>
...which screams at me "You're not doing it right!"
What is the right way to accomplish this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我知道这是一个老问题,但我这样做是这样的:
使用它作为你的课程:
I know this is an old question but I did it like:
Use this as your class:
甚至更简单...
ASP.NET
CSS
Even easier...
ASP.NET
CSS
使用 css 为这些特定元素添加右边距。一般来说,我会构建控件,然后运行它以查看生成的 html 结构是什么样的,然后使 css 仅更改这些元素。
最好通过设置类来做到这一点。将
CssClass="myrblclass"
属性添加到列表声明中。您还可以以编程方式向项目添加属性,这将从另一侧出现。
这可能对您更好,因为您可以为除最后一个之外的所有属性添加该属性。
Use css to add a right margin to those particular elements. Generally I would build the control, then run it to see what the resulting html structure is like, then make the css alter just those elements.
Preferably you do this by setting the class. Add the
CssClass="myrblclass"
attribute to your list declaration.You can also add attributes to the items programmatically, which will come out the other side.
This may be better for you since you can add that attribute for all but the last one.
如果重复布局是表格,您还可以使用 cellspacing 和 cellpadding 属性。
you can also use cellspacing and cellpadding properties if repeat layout is table.
尽管如此,这种情况的最佳方法是设置自定义 CSS 样式 - 另一种选择是:
Width
属性并根据需要设置百分比查看更适合您的目的。在我想要的场景中,我需要设置 (2) 个单选按钮/项目,如下所示:
示例:
渲染结果:
Even though, the best approach for this situation is set custom CSS styles - an alternative could be:
Width
property and set the percentaje as you see more suitable for your purposes.In my desired scenario, I need set (2) radiobuttons/items as follows:
Example:
Rendered result: