When using the DataGrid control to add radio buttons, if you add the RadioButton server control directly to the template, due to the mechanism of .Net, these RadioButtons cannot appear in the same group on the client. At this time we can use the Radio tag to achieve this.
The following is the HMTL page code
<form id="Form1" method="post" runat="server">
<asp:datagrid id="DataGrid1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<input type="radio" name="rdo" <%# GetChecked(DataBinder.Eval(Container, "DataItem")) %> value='<%# DataBinder.Eval(Container, "DataItem") %>'>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem") %>' ID="Label1">
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid><br>
<asp:Button id="btnOk" runat="server" Text="OK"></asp:Button>
The following is the data binding code in Page_Load
Dim arr As New ArrayList
arr.Add("News Comprehensive")
arr.Add("variety show")
arr.Add("movie")
arr.Add("Education")
arr.Add("Drama")
arr.Add("Military")
arr.Add("Sports")
DataGrid1.DataSource = arr
DataGrid1.DataBind()
The following is the code to obtain the selected item in btnOk_Click
Response.Write(Request.Form("rdo"))
The following is the function to set which Radio in the binding item is selected
Public Function GetChecked(ByVal str As String) As String
If str = Request.Form("rdo") Then
Return "checked"
Else
Return ""
End If
End Function