我怎么项目之间在ASP.NET单选按钮列表添加空间 [英] How do I add space between items in an ASP.NET RadioButtonList

查看:195
本文介绍了我怎么项目之间在ASP.NET单选按钮列表添加空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP.NET单选按钮列表,使用显示四个项目的 RepeatDirection =水平以显示它们在一行。我使用的 RepeatLayout =流,以避免标记为表。但是,这会导致在列表中的项目的旁边放置到彼此,其中不好看。

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.

所以,我尝试了表格布局采取 CELLSPACING 和/或 CELLPADDING 性能优势。不幸的是,这些性质影响到垂直和水平间距/填充的表内,因此,虽然我得到的水平间距,我也得到不希望的垂直间距

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&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>

...这尖叫看着我你不这样做是正确的!

...which screams at me "You're not doing it right!"

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

What is the right way to accomplish this?

推荐答案

使用CSS的权利保证金添加到这些特定元素。一般来说,我会生成控件,然后运行它看到生成的HTML结构是什么样的,然后让CSS改变只是这些元素。

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通过设置来实现这个目的。在的CssClass =myrblclass属性添加到列表的声明。

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.

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

这可能是对你更好,因为你可以添加属性为所有,但最后一个。

This may be better for you since you can add that attribute for all but the last one.

这篇关于我怎么项目之间在ASP.NET单选按钮列表添加空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆