2009-07-10 28 views

Trả lời

5

Trong chức năng javascript của bạn nơi bạn muốn truy vấn danh sách, sử dụng mã này ..

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

để thiết lập một nhãn mẫu với kết quả của RadioButtonList chọn của bạn, bạn có thể làm điều này ...

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

... giả định rằng SearchOptions là điều khiển trong đó các nút radio được hiển thị. –

+0

chính xác - ví dụ được cập nhật để cố gắng làm rõ. –

+0

Cảm ơn scott. Điều này hoạt động hoàn hảo. – zSynopsis

1

Ví dụ làm việc here.

Bộ chọn tôi đã sử dụng để nhận các nút radio sẽ lấy tất cả các nút radio có lớp ofinterest trên trang.

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

Nếu bạn muốn phạm vi bộ chọn thêm và không ngại viết JS trực tiếp vào aspx/ascx, bạn có thể sử dụng giải pháp của Scott ở trên thay thế. Nhưng nếu bạn cung cấp cho các nút bạn quan tâm đến một tên lớp đã biết, bạn có thể đặt JS này trong một tệp .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; 
    } 
} 
Các vấn đề liên quan