2009-07-10 75 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; 
    } 
} 
相关问题