2011-06-29 12 views
0

asp:CustomValidator javascript関数で親を取得して、関連するチェックボックスがオンになっているかどうかをチェックする方法を教えてください。asp:CustomValidator javascript関数で親を取得する方法

例:

 <tr> 
      <th class="graytext r">Add Reps to Team:</th> 
      <td>   
      <asp:GridView ID="grid" runat="server" AutoGenerateColumns="False" DataKeyNames="EmployeeID" 
        DataSourceID="dsEmployees" EnableViewState="false" 
        GridLines="None" CssClass="clGridDirectory"> 
        <Columns> 
         <asp:TemplateField > 
         <ItemTemplate> 
          <asp:CheckBox runat="server" ID="employee_name" CssClass="employee_name" Text='<%# Eval("fullname") %>'/> 
          <asp:HiddenField runat="server" ID="employeeidToRep" Value='<%# Eval("employeeid") %>'/> 

          <asp:TextBox runat="server" ID="repID" Text='<%# Eval("rep_id") %>' /> 

          <asp:CustomValidator id="CustomValidator2" runat="server" 
           ControlToValidate = "repID" 
           ErrorMessage = "" 
           ClientValidationFunction="test" > 
          </asp:CustomValidator> 
         </ItemTemplate> 
         </asp:TemplateField> 
        </Columns> 
        </asp:GridView>  
       <asp:SqlDataSource ID="dsEmployees" runat="server" ConnectionString="<%$ ConnectionStrings:TestConnectionString %>" 
        SelectCommand="app_staff_without_team_select" SelectCommandType="StoredProcedure"> 
       </asp:SqlDataSource>   
      </td> 
     </tr> 

のjQueryコード:

function test(oSrc, args) { 

    var $tb = $('input[id$=employee_name]'); 
    // only validate if an <asp:Checkbox> called chkOtherCheckbox is ticked 
    alert(args.Value.toString()) 
    if ($('input:checkbox[id$=chkOtherCheckbox]').is(':checked')) 
     alert('checked') 
    else 
     alert('no checked') 

} 

私がそれを使用できるように、どのように私はテスト機能で親を取得することができます

私は、次のコードを持っています関連するチェックボックスがチェックされているかどうかを確認しますか?

答えて

0

このコードを使用すると、最も近いチェックボックスの状態を取得できます。

function test(oSrc, args) {  
    var nearestCheckBox= $(oSrc).parent().find('input:checkbox:first'); 
      var state=nearestCheckBox.attr('checked');//use this variable 

} 
関連する問題