如何在VB.net中按字符串创建单选按钮?
我必须创建1个包含多个单选按钮的表。
我的代码
Dim i As Integer = 0
Dim str As String = "<table><tr><td><asp:radiobutton ID='Radiobutton" & i & "' runat='server' Text='" & i & "' /></td></tr></table>"
Response.Write(str)
注意:我必须使用单选按钮控制.Net
答案 0 :(得分:0)
你不能以这种方式使用RadioButton,因为它是一个服务器控件。你必须在响应上写纯HTML:
Dim i As Integer = 0
Dim str As String = "<table><tr><td><input id='Radiobutton' type='radio' name='Radiobutton' value='" & i & "' />" & i & "</td></tr></table>"
Response.Write(str)
或者你必须使用HtmlGenericControl而不直接写在Response:
Dim table as New HtmlGenericControl("table");
Dim tr as New HtmlGenericControl("tr");
Dim td as New HtmlGenericControl("td");
Dim radio as New RadioButton();
table.Controls.Add(tr);
tr.Controls.Add(td);
td.Controls.Add(radio);
Page.Controls.Add(table);