01.<%@ Page Language="C#" %>
02.
03.<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
04.
05.<script runat="server">
06.
07. protected void lv_ItemCreated(object sender, ListViewItemEventArgs e)
08. {
09. //RadioButton rb = e.Item.FindControl("rb") as RadioButton;
10. ////if (rb != null)
11. //{
12. // rb.Attributes["name"] = "productlist";
13. //}
14. }
15.
16. protected void lv_ItemDataBound(object sender, ListViewItemEventArgs e)
17. {
18. //RadioButton rb = e.Item.FindControl("rb") as RadioButton;
19. //if (rb != null)
20. //{
21. // rb.InputAttributes["name"] = lv.ID + "_table1";
22. //}
23. }
24.
25. protected void lv_PreRender(object sender, EventArgs e)
26. {
27. foreach (ListViewItem item in lv.Items)
28. {
29. RadioButton rb = item.FindControl("rb") as RadioButton;
30. if (rb != null)
31. {
32. rb.InputAttributes.Clear();
33. rb.InputAttributes.Add("name", "lv_table1");
34. }
35. }
36. }
37.</script>
38.
39.<html xmlns="http://www.w3.org/1999/xhtml">
40.<head runat="server">
41. <title></title>
42.</head>
43.<body>
44. <form id="form1" runat="server">
45. <div>
46. <asp:ListView ID="lv" runat="server" DataSourceID="SqlDataSource1"
47. Visible="true" onprerender="lv_PreRender">
48. <LayoutTemplate>
49. <table runat="server" id="table1">
50. <tr runat="server" id="itemPlaceHolder"></tr>
51. </table>
52. </LayoutTemplate>
53. <ItemTemplate>
54. <tr runat="server">
55. <td runat="server">
56. <input type="radio" name="lv_table1" title='<%#Eval("ProductName") %>' />
57. <%#Eval("ProductName") %>
58. </td>
59. </tr>
60. </ItemTemplate>
61. </asp:ListView>
62. <br />
63. ---------------------------------------
64. <asp:RadioButtonList ID="RadioButtonList1" runat="server"
65. DataSourceID="SqlDataSource1" DataTextField="ProductName"
66. DataValueField="ProductName" Visible="true">
67. </asp:RadioButtonList>
68. <asp:SqlDataSource ID="SqlDataSource1" runat="server"
69. ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
70. SelectCommand="SELECT Top 5 [ProductName] FROM [Alphabetical list of products]">
71. </asp:SqlDataSource>
72. </div>
73. </form>
74.</body>
75.</html>