2012-09-19 96 views
3

如何將超鏈接添加到RadioButtonList將超鏈接添加到RadioButtonList

我試過以下,但它仍然呈現爲純文本。

<asp:RadioButtonList runat="server" id="rdlTest"> 
    <asp:ListItem Value="1" Text="<a href='Page2.aspx?1'>A</a>"></asp:ListItem> 
    <asp:ListItem Value="2" Text="<a href='Page2.aspx?2'>B</a>"></asp:ListItem> 
</asp:RadioButtonList> 

我知道下面的作品,但我想用RadioButtonList,而不是RadioButton

<asp:RadioButton runat="server" ID="rdoTest" Text="<a href='Page2.aspx?1'>A</a>" /> 

UPDATE

一些其他的代碼被搞亂這個了。所以我的原始代碼沒有問題。 我有一個功能,清除並重新加載Page_Loadrdl.Items.Add(new ListItem("1","A") rdlTest,並重寫工作標記。

+0

我想你必須在rowdatabound事件中處理這個事情,通過標記這個不會工作。 – JonH

+0

您提供的代碼在我的項目中呈現爲正確的超鏈接... –

+0

Ray您是否可以發佈代碼,在其中編輯您發佈的原始代碼以顯示代碼,以便爲您減少任何混淆錯誤 – MethodMan

回答

1

你就不能這樣做......

<asp:CheckBoxList ID="chk" runat="server"> 

     <asp:ListItem Value="0"><a href="http://www.asp.net">asp.net</a></asp:ListItem> 

     <asp:ListItem Value="1"><a href="http://forums.asp.net">forums.asp.net</a></asp:ListItem> 

</asp:CheckBoxList> 

RadioButtonList的和的CheckBoxList應該工作類似。

+0

我嘗試過'RadioButtonList'但仍顯示爲純文本。 –

+0

你可能想改變的asp.net 到 的"asp.net MethodMan

+0

@DJKRAZE,嘗試了 –

0

你可以隨時爲它們分配一個id,然後用Javascript(或jQuery)連接一個onclick事件。

<asp:ListItem Value="1" Text="A" ID = "A"></asp:ListItem> 

$('#A').click(function(){ 

window.location='Page2.aspx?1' 

} 
+1

我想讓用戶選擇單選按鈕,但是沒有任何改變,謝謝你, –

+0

嘗試在ListItem中放置一個標籤,並將onclick事件掛接到標籤。 – IronMan84