2011-05-11 55 views
1

我創建水平放置的單選按鈕,我展示了一些,尚未出現其他取決於一些條件保留在asp.net中動態創建的單選按鈕的位置?

如果我設置爲false可見,這個地方將在下一個單選按鈕被佔用, 有沒有放任何方式空間呢?

基本創作單選按鈕的:(只測試代碼)

    Dim rdButton As New RadioButton 
        rdButton.Text = "test" 
        rdButton.GroupName = "test2" 
        cell.Controls.Add(rdButton) 
        Dim rdButton2 As New RadioButton 
        rdButton2.Text = "test2" 
        rdButton2.GroupName = "test2" 
        rdButton2.Visible=False 
        cell.Controls.Add(rdButton2) 
        Dim rdButton3 As New RadioButton 
        rdButton3.Text = "test" 
        rdButton3.GroupName = "test2" 
        cell.Controls.Add(rdButton3) 

感謝

+0

它們水平放置 – Bart 2011-05-11 05:44:47

+0

對不起。我改變了這個以反映水平佈局。請再次檢查'[test](http://jsfiddle.net/xh9XN/3/)'鏈接。 – Jeremy 2011-05-11 09:46:02

回答

2

你可以使用CSS類隱藏的單選按鈕。要做到這一點,你可以做一些與此類似:

的CSS:

.radio-spacer { 
visibility: hidden; 
} 

ASP.Net控制:

<asp:RadioButton ID="RadioButton1" Text="Blue" GroupName="Hats" 
runat="server" /> 
<asp:RadioButton CssClass="radio-spacer" ID="RadioButton2" Text="Purple" 
GroupName="Hats" runat="server" /> 
<asp:RadioButton ID="RadioButton3" Text="Orange" GroupName="Hats" 
runat="server" /> 

或替代(只用HTML):

<label> 
<input type="radio" name="hatColour" value="blue" id="hatColour_0" /> 
Blue</label> 
<label class="radio-spacer"> 
<input type="radio" name="hatColour" value="purple" id="hatColour_0" /> 
Purple</label> 
<label> 
<input type="radio" name="hatColour" value="orange" id="hatColour_1" /> 
Orange</label> 

在上面的例子中,你會看到2個單選按鈕(藍色和橙色),你會看到紫色應該在哪裏。你可以測試它here

+0

他們水平定位 – Bart 2011-05-11 05:44:55

+0

我改爲radiobuttonlist,這完美的工作:rdBtnList.Items.FindByText(lstItem.Text).Attributes.CssStyle.Add(「知名度」,「隱藏」),但下面的作品,但不會有一個空的空間:rdBtnList.Items.FindByText(lstItem.Text).Attributes.CssStyle.Add(「display」,「none」) – Bart 2011-05-16 00:56:31

+0

這就是CSS'visibility'和'display'應該如何工作。 'display'不繪製物體的邊界,而'visibility'仍然繪製物體的邊界。 – Jeremy 2011-05-18 00:26:24

相關問題