2016-07-16 10 views
1

textbox & ButtonのネストされたGridviewがあります。 asp.netでjqueryを使用してButton Clickを入力したときに表示されるtextboxの値を表示する方法私はネストされたGridviewのボタンクリックからTextBox値を取得する方法

function showText() {    
      var text= $("#TextBox1").val(); 
      alert(text); 
      return false; 
     } 

を使用している例

<asp:GridView ID="GridParent" runat="server"> 
<Columns> 
    <asp:TemplateField> 
    <ItemTemplate> 
     <table> 
     <tr> 
     <td> 
      ----------- 
      ----------- 
     </td> 
     <td> 
     <asp:GridView ID="GridChild" runat="server"> 
      <Columns> 
      <asp:TemplateField> 
      <ItemTemplate> 
       <asp:Textbox ID="TextBox1" runat="server"></asp:TextBox> 
       <asp:Button ID="Button1" runat="server" Text="Button" onclick=showText(); return false; /> 
      </ItemTemplate> 
      </asp:TemplateField> 
     </Columns> 
     </asp:GridView> 
     </td> 
     </tr> 
     </table> 
    </ItemTemplate> 
    </asp:TemplateField> 
</Columns> 
</asp:GridView> 

jQueryのために
私はstackoverflowの正確な質問を見つけましたが、私はjQueryのを使用して、ネストされたGridViewの中にテキストボックスの値を取得したいので、私の質問は少し異なっていますC#あなたのweb.config

答えて

0

をコーディングして、このようなclientIDModeを追加していない:

をその後

$(function() { 
    $("#Button1").click(function(e) { 
     e.preventDefault(); 
     alert($("#TextBox1").val()); 
    }); 
}); 
+0

その動作していない仲間 – user6503334

+0

あなたのjQueryをロードしていますか? –

+0

私の他のjquery検証はうまく動作します – user6503334

0

あなたが試すことができます。

<asp:TemplateField> 
    <ItemTemplate> 
     <asp:TextBox ID="TextBox1" runat="server" /> 
     <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="showText(this); return false;" /> 
    </ItemTemplate> 
</asp:TemplateField> 

クリックされたボタンと同じテーブルセル内のテキストボックスを探し、次のshowText機能で:

function showText(btn) { 
    alert($(btn).closest('td').find('input[type=text]').val()); 
} 


更新

other questionによると、テキストボックスとボタンはdivコンテナの内側にある可能性があります。その場合は、機能showTextは次のようになります。

function showText(btn) { 
    alert($(btn).closest('div').find('input[type=text]').val()); 
} 
関連する問題