如何使用jquery从gridview获取文本框值

时间:2012-11-25 14:04:01

标签: jquery asp.net gridview

如何使用jquery点击链接按钮从gridview中发送文本框值 这是我的gridview

  <asp:GridView ID="gvEmployee" runat="server" AutoGenerateColumns="false" GridLines="Both">
            <Columns>
                <asp:TemplateField HeaderText="Email">
                    <ItemTemplate>
                        <asp:TextBox ID="txtEmail" runat="server" Text='<%#Eval("Emailid") %>'></asp:TextBox>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Name">
                    <ItemTemplate>
                        <asp:TextBox ID="txtName" runat="server" Text='<%#Eval("Name") %>'></asp:TextBox>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:LinkButton ID="lnkgettext" runat="server" Text="Gettextboxvalue"></asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>

我试过像

这样的东西
  alert($(this).parent("td").parent("tr").find("input:text").val());

我能找到文本框的第一个值 但是面临一个问题,即从第二个td获得下一个文本框值,即txtName 请建议 如果你有任何javascript解决方案,也建议

4 个答案:

答案 0 :(得分:1)

愿这对你有帮助......

    function GVtxtAmount() {
    var GVMaintainReceiptMaster = document.getElementById('<%= GVMaintainReceiptMaster.ClientID %>');

    for (var rowId = 1; rowId < GVMaintainReceiptMaster.rows.length; rowId++) {
        var txtbx = GVMaintainReceiptMaster.rows[rowId].cells[0].children[0];
        alert(txtbx.value);
    }
    return false;
}

答案 1 :(得分:0)

您可以按如下方式使用结束选择器

 $( "[ @id *= 'txtEmail']" ).text();

这是一个关于如何找到像选择

这样的元素的好链接
[http://www.bennadel.com/blog/1003-Cool-jQuery-Predicate-Selectors.htm][1]

你会发现这样的

 //first find the tr 
 var tr= $(this).parent("td").parent("tr");
 and then use like selector with.

 var Email=$(this).parent("td").parent("tr").find($( "[ @id *= 'txtEmail']" )).val();
 var Name= $(this).parent("td").parent("tr").find($( "[ @id *= 'txtName']" )).val();

答案 2 :(得分:0)

$('#<%=lnkgettext.ClientID %>').click(function(){
    var email=$(this).parent('td').parent('tr').find('#<%=txtEmail.ClientID%>').val();        
    var name=$(this).parent('td').parent('tr').find('#<%=txtName.ClientID%>').val();
}

$(this).parent("td").parent("tr").each(function(){
    $(this).find('td').each(function(){
        //Do whatever you want, you can use $(this) to get value of current cell
    })
})

答案 3 :(得分:0)

试试这个,它应该可以正常工作

$('a[id$=lnkgettext]').click(function(){
    var email=$(this).parent('tr').find('input[id=txtEmail]').val();        
    var name=$(this).parent('tr').find('input[id=txtName]').val();
    alert(email+" "+name);
}
相关问题