2014-09-26 80 views
2

我知道这在过去一直在为我工作,但我尝试设置我的radiobutton的值将被忽略,并且该值被设置为我单选按钮的ID。在ASP上的设置值:RadioButton

ASP.Net

<asp:RadioButton ID="rb" runat="server" /> 

背后

//Test 1 
rb.InputAttributes.Add("value", "foo"); 

//Test 2 
rb.InputAttributes["value"] = "foo"; 

代码HTML输出

<input id="rb" type="radio" name="rb" value="rb" /> 

缺少什么我在这里?

设置ASP.Net标记中的值正在工作,但我宁愿从代码隐藏这样做。

回答

5

你可以简单的做:

rb.Attributes.Add("value", "foo"); 

HTML输出:

<input id="ContentPlaceHolder1_rb" type="radio" name="ctl00$ContentPlaceHolder1$rb" value="foo"> 
+0

这里也亚克看看http://www.daveparslow.com/2007/08/assigning-value-to-aspnet-checkbox.html – 2014-09-26 09:01:43