2009-07-10 92 views

回答

5

在您要查詢的列表,使用此代碼的JavaScript函數..

var selected = jQuery('#<%= MyRadioButtonList.ClientID %> input:checked').val(); 
// or ... 
var selected = $('#<%= MyRadioButtonList.ClientID %> input:checked').val(); 

設置與您選擇的單選按鈕列表結果的樣本標籤,你可以這樣做...

$(document).ready(function(){ 
    var selected = $('#<%= MyRadioButtonList.ClientID %> input:checked').val(); 
    $("#<%= MySampleLabel.ClientID %>").text(selected); 
} 
+0

...假設SearchOptions是呈現單選按鈕的控件。 – 2009-07-10 16:19:18

1

工作示例here

我用來獲取單選按鈕的選擇器將抓取頁面上類ofinterest的所有單選按鈕。

$(function(){ 
    var value = $('input.ofinterest:checked').val(); 
    $('#result').text(value); 
}); 

如果你想範圍選擇器還,你不介意直接在ASPX/ASCX寫你的JS,你可以使用上面,而不是斯科特的解決方案。但是如果你給這些按鈕你感興趣的是一個已知的類名,那麼你可以把這個JS放在一個.js文件中。

1
protected void radioButton_CheckedChanged(object sender, EventArgs e) 
{ 
    throw new ApplicationException("Radio Changed"); 
    RadioButton rb = (RadioButton)sender; 
    TextBox tbexact = (TextBox)this.UpdatePanel1.FindControl("TextBoxExact"); 
    TextBox tbpartial = (TextBox)this.UpdatePanel1.FindControl("TextBoxPartial"); 
    DropDownList dropdown = (DropDownList)this.UpdatePanel1.FindControl("DropDownListCountries"); 

    RadioButton rbc = (RadioButton)this.UpdatePanel1.FindControl("RadioButtonExact"); 
    if (tbexact == null) 
    throw new ApplicationException("Could not find control"); 
    else 
    throw new ApplicationException("Found it"); 
    if (rbc != null && rb.Equals(rbc)) 
    { 
    tbpartial.Enabled = false; 
    dropdown.Enabled = false; 
    mCriteria = SearchCriteria.Exact; 
    } 
    rbc = (RadioButton)this.UpdatePanel1.FindControl("RadioButtonPartial"); 
    if (rbc != null && rb.Equals(rbc)) 
    { 
    tbexact.Enabled = false; 
    dropdown.Enabled = false; 
    mCriteria = SearchCriteria.Partial; 
    } 
    rbc = (RadioButton)this.UpdatePanel1.FindControl("RadioButtonPerCountry"); 
    if (rbc != null && rb.Equals(rbc)) 
    { 
    tbexact.Enabled = false; 
    tbpartial.Enabled = false; 
    mCriteria = SearchCriteria.Country; 
    } 
} 
相關問題