<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>
测试结果为
时间: 2024-10-13 03:02:17