假設你正在使用一個asp: RadioButton,則一種方法是將RadioButton的AutoPostBack屬性設置爲true。
然後在服務器端的處理程序中,您可以更改文本。
顯然這是有代價的。
例如
<asp:RadioButton ID="ctrlRadioButton" runat="server" AutoPostBack="True"
oncheckedchanged="ctrlRadioButton_CheckedChanged" Text="Select this" />
在你的代碼類
然後
protected void ctrlRadioButton_CheckedChanged(object sender, EventArgs e)
{
ctrlRadioButton.Text = "New Text";
}
更新:
如果創建動態的單選按鈕:
protected void Page_Init(object sender, EventArgs e)
{
for (int i = 0; i < 4; ++i)
{
RadioButton rb = new RadioButton() { AutoPostBack = true, Text = "Initial text" };
rb.CheckedChanged += RadioButton_CheckedChanged;
Form.Controls.Add(rb); // Or add to a panel if you prefer
}
}
和處理程序
protected void RadioButton_CheckedChanged(object sender, EventArgs e)
{
RadioButton rb = (RadioButton)sender;
rb.Text = "New Text";
}
需要你寫詳細介紹一下aspx頁面。您使用服務器控件或簡單的HTML的複選框? – Raghurocks