如何从嵌套Gridview中的按钮单击中获取TextBox值 [英] How to Get TextBox value from button click in Nested Gridview
问题描述
我有一个嵌套Gridview,其中包含 textbox&按钮
列。如何在按钮时在alert中显示
textbox
的值通过在asp.net中使用jquery来完成 b $ b例如
< asp:GridView ID =GridParentrunat =server>
<列>
< asp:TemplateField>
< ItemTemplate>
< table>
< tr>
< td>
-----------
-----------
< / td>
< td>
< asp:GridView ID =GridChildrunat =server>
<列>
< asp:TemplateField>
< ItemTemplate>
< asp:Textbox ID =TextBox1runat =server>< / asp:TextBox>
< asp:Button ID =Button1runat =serverText =Buttononclick = showText();返回false; />
< / ItemTemplate>
< / asp:TemplateField>
< /列>
< / asp:GridView>
< / td>
< / tr>
< / table>
< / ItemTemplate>
< / asp:TemplateField>
< /列>
< / asp:GridView>
我正在使用的JQuery
function showText(){
var text = $(#TextBox1)。val();
alert(text);
返回false;
$ / code>
我在stackoverflow中发现了一个确切的问题,但我的问题有点不同,因为我想通过使用JQuery来获取嵌套gridview中的textbox值而不是使用C#编码
您可以尝试:
< asp:TemplateField>
< ItemTemplate>
< asp:TextBox ID =TextBox1runat =server/>
< asp:Button ID =Button1runat =serverText =ButtonOnClientClick =showText(this); return false; />
< / ItemTemplate>
< / asp:TemplateField>
与以下 showText
函数对于与单击按钮相同的表格单元格中的文本框:
function showText(btn){
警报($(BTN).closest( 'TD')找到( '输入[类型=文本]')VAL());
}
更新
根据您的 other question ,文本框和按钮可能位于div容器内。如果是这种情况,函数 showText
应该是:
函数showText(btn){
alert($(btn).closest('div')。find('input [type = text]')。val());
}
I have a Nested Gridview having textbox & Button
column. How to display value of textbox
in alert when Button Click
by using jquery in asp.net.
For Example
<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 which i'm using
function showText() {
var text= $("#TextBox1").val();
alert(text);
return false;
}
i found a exact question in stackoverflow but my question is little different because i want to get textbox value in nested gridview by using JQuery not with C# Coding
You can try:
<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>
with the following showText
function, which looks for a text box in the same table cell as the button that was clicked:
function showText(btn) {
alert($(btn).closest('td').find('input[type=text]').val());
}
UPDATE
According to your other question, the text box and the button could be inside of a div container. If that is the case, the function showText
should be:
function showText(btn) {
alert($(btn).closest('div').find('input[type=text]').val());
}
这篇关于如何从嵌套Gridview中的按钮单击中获取TextBox值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!