2017-10-04 5 views
0

ネストされたGridviewとコントロールを見つけるのに助けが必要です。ラベル jqueryを使用してjquery - ネストされたGridviewとその中のコントロールを見つける

私は以下の計算を行う途中ですjqueryコードです。

$("#<%=gvSupplierList.ClientID %>").each(function() { 

    //hardcoded control id of parent gridview 
    $(this).find('span[id$="gvSupplierList_lblsizeofopt_0"]').text('0.01'); 

    //hardcoded control id of child/nested gridview 
    $("#gvSupplierList_gvCustomerList_0 > tbody > tr").each(function() { 

     //hardcoded control id of child/nested control 
     $(this).find('input[id$="gvSupplierList_gvCustomerList_0_txtsizeofopt_0"]').val(); 

    }); 

}); 

ありがとうございます。

答えて

0

FindControlを使用して、コントロールツリーを上に移動し、子のGridViewの行に正しいTextBoxを配置する必要があります。

<asp:GridView ID="GridViewParent" runat="server" OnRowDataBound="GridView1_RowDataBound"> 
    <Columns> 
     <asp:TemplateField> 
      <ItemTemplate> 

       <asp:GridView ID="GridViewChild" runat="server"> 
        <Columns> 
         <asp:TemplateField> 
          <ItemTemplate> 

           <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> 

          </ItemTemplate> 
         </asp:TemplateField> 
        </Columns> 
       </asp:GridView> 

      </ItemTemplate> 
     </asp:TemplateField> 
    </Columns> 
</asp:GridView> 

<script type="text/javascript"> 
    $("#<%= ((GridView)GridViewParent.Rows[1].FindControl("GridViewChild")).Rows[2].FindControl("TextBox1").ClientID %>").val("TextBox is found!"); 
</script> 

このスニペットでは、親の行1と子の行2のTextBoxが配置され、テキストが設定されています。

それとも、あなたはまた、私はそれが可能と思われる行を知らないでこの

<script type="text/javascript"> 
    var parentRow = 3; 
    var childRow = 5; 

    $('#<%= GridViewParent.ClientID %> table').each(function (index, element) { 
     if (index == parentRow) { 
      $('#' + element.id + ' input[type="text"]').each(function (indexNested, elementNested) { 
       if (indexNested == childRow) { 
        $(this).val("TextBox is found!") 
       } 
      }); 
     } 
    }); 
</script> 
+0

シングを行うことができますjQUewryに両方の行を知っていれば。そのシナリオをより良い方法で説明しましょう。関数は、同じネストされたグリッド内のすべてのテキストボックスを計算し、親グリッドにあるラベル内の合計に追加するためにトリガーするネストされたグリッドのテキストボックスから実行されます。私はロジックが何であるかを知っていますが、実装するためにjquery構文を使用するのは難しいと思っています。ご協力いただきありがとうございます。 –

関連する問題