2012-09-19 90 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