Today we will See How to Get TextBox value from GridView using JavaScript..?
First Design Gridview as:
- <asp:GridView ID="GVReue" runat="server" ">
- <Columns>
- <asp:TemplateField HeaderText="Item Name">
- <ItemTemplate>
- <asp:Label ID="lblItemName" Text=' <%# Eval("fldItemName") %>'
- runat="server"></asp:Label>
- </ItemTemplate>
- </asp:TemplateField>
- <asp:TemplateField HeaderText="Quantity">
- <ItemTemplate>
- <asp:TextBox ID="txtQty" ToolTip=' <%# Eval("fldQuntity") %>' onblur="Calculation(this.value)"
- runat="server" />
- </ItemTemplate>
- </asp:TemplateField>
- </Columns>
- <EmptyDataTemplate>
- No Record Found....!!!
- </EmptyDataTemplate>
- </asp:GridView>
Design as:
Then Use Script in Head tag as:
- <script type="text/javascript">
- function Calculation() {
- var grid = document.getElementById("<%= GVReue.ClientID%>");
- for (var i = 0; i < grid.rows.length - 1; i++) {
- var txtAmountReceive = $("input[id*=txtQty]")
- if (txtAmountReceive[i].value != '') {
- alert(txtAmountReceive[i].value);
- }
- }
- }
- </script>
Then Get value of TxtQty Textbox as