首页 > 代码库 > 使用javascript获取gridview中的textbox值

使用javascript获取gridview中的textbox值

<body>    <form id="form1" runat="server">    <div>    <asp:gridview ID="GVReue" runat="server" AutoGenerateColumns="False"             DataSourceID="SqlDataSource1">        <Columns>                       <asp:TemplateField HeaderText="ProductName" >               <ItemTemplate>                    <asp:TextBox ID="txtQty" runat="server" ToolTip=<%# Eval("ProductName") %> onblur="Calculation(this.value)"></asp:TextBox>                 </ItemTemplate>            </asp:TemplateField>                    </Columns>        </asp:gridview>    <asp:SqlDataSource ID="SqlDataSource1" runat="server"             ConnectionString="<%$ ConnectionStrings:testConnectionString %>"             SelectCommand="SELECT * FROM [Products]"></asp:SqlDataSource>    </div>    </form></body></html>

javascript代码

<script type="text/javascript">        function Calculation() {            var grid = document.getElementById("<%= GVReue.ClientID%>");            for (var i = 0; i < grid.rows.length - 1; i++) {                //alert(i);                var txtAmountReceive = $("input[id*=txtQty]")                //alert(txtAmountReceive);                if (txtAmountReceive[i].value != ‘‘) {                    alert(txtAmountReceive[i].value);                }            }                    }  </script>  

技术分享

测试结果为

技术分享

使用javascript获取gridview中的textbox值