如果您有内容占位符,您可以将单选按钮列表控件添加到那里吗?
在母版页上:
<asp:ContentPlaceHolder id="ContentPlaceHolderForRadioButtonList" runat="server">
</asp:ContentPlaceHolder>
一些链接,包含下一页使用的请求变量。
<a href="RadioButtonList.aspx?ref=first" >Link 1</a>
<a href="RadioButtonList.aspx?ref=second" >Link 2</a><br />
<a href="RadioButtonList.aspx?ref=third" >Link 3</a><br />
<a href="RadioButtonList.aspx?ref=forth" >Link 4</a><br />
<a href="RadioButtonList.aspx?ref=fifth" >Link 5</a><br />
<a href="RadioButtonList.aspx?ref=sixth" >Link 6</a>
现在,在带有单选按钮列表的页面上,将其添加到内容占位符中。
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolderForRadioButtonList" Runat="Server">
<!-- radio button list to be dynamically populated-->
<asp:RadioButtonList ID="RadioButtonList1" runat="server">
</asp:RadioButtonList>
</asp:Content>
单选按钮列表.aspx:
用于根据传入的信息动态填充单选按钮列表的代码。
Partial Class RadioButtonList
Inherits System.Web.UI.Page
Private selection As String = ""
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
selection = IIf(Request.QueryString("ref") IsNot Nothing, Request.QueryString("ref"), "")
If selection = "first" Then
RadioButtonList1.Items.Add(New ListItem("first", "1"))
RadioButtonList1.Items.Add(New ListItem("third", "3"))
RadioButtonList1.Items.Add(New ListItem("fifth", "5"))
ElseIf selection = "second" Then
RadioButtonList1.Items.Add(New ListItem("second", "2"))
RadioButtonList1.Items.Add(New ListItem("forth", "4"))
RadioButtonList1.Items.Add(New ListItem("sixth", "6"))
Else
RadioButtonList1.Items.Add(New ListItem("first", "1"))
RadioButtonList1.Items.Add(New ListItem("second", "2"))
RadioButtonList1.Items.Add(New ListItem("third", "3"))
RadioButtonList1.Items.Add(New ListItem("forth", "4"))
RadioButtonList1.Items.Add(New ListItem("fifth", "5"))
RadioButtonList1.Items.Add(New ListItem("sixth", "6"))
End If
'set the selected radio button
For i As Integer = 0 To RadioButtonList1.Items.Count - 1
If RadioButtonList1.Items(i).Text = selection Then
RadioButtonList1.Items(i).Selected = True
Exit For
End If
Next
End Sub
End Class
希望您能在这里找到有用的东西。