How to Get TextBox value from GridView using JavaScript

First Design Gridview as :

  1. <asp:GridView ID="GVReue" runat="server" ">  
  2.   <Columns>  
  3.         <asp:TemplateField HeaderText="Item Name">  
  4.     <ItemTemplate>  
  5.         <asp:Label ID="lblItemName" Text=' <%# Eval("fldItemName") %>'  
  6.            runat="server"></asp:Label>  
  7.     </ItemTemplate>  
  8.         </asp:TemplateField>  
  9.         <asp:TemplateField HeaderText="Quantity">  
  10.     <ItemTemplate>  
  11.         <asp:TextBox ID="txtQty" ToolTip=' <%# Eval("fldQuntity") %>' onblur="Calculation(this.value)"  
  12.             runat="server" />  
  13.     </ItemTemplate>  
  14.        </asp:TemplateField>  
  15.  </Columns>  
  16.         <EmptyDataTemplate>  
  17.             No Record Found....!!!  
  18.         </EmptyDataTemplate>  
  19. </asp:GridView>  
Design as

table with text fields

Then Use Script in Head tag as
  1. <script type="text/javascript">  
  2.     function Calculation() {  
  3.     var grid = document.getElementById("<%= GVReue.ClientID%>");  
  4.     for (var i = 0; i < grid.rows.length - 1; i++) {  
  5.     var txtAmountReceive = $("input[id*=txtQty]")  
  6.     if (txtAmountReceive[i].value != '') {  
  7.     alert(txtAmountReceive[i].value);  
  8.       }  
  9.       }  
  10. }  
  11. </script>  
Then Get value of TxtQty Textbox as

local host

Ebook Download
View all
Learn
View all