---
title: "How to find text-box in GridView using Javascript"  
description: "How to find text-box in GridView using Javascript"  
author: "Anonymous User"  
published: 2014-12-18  
updated: 2014-12-19  
canonical: https://www.mindstick.com/forum/12792/how-to-find-text-box-in-gridview-using-javascript  
category: "asp.net"  
tags: ["c#", "javascript", "gridview"]  
reading_time: 2 minutes  

---

# How to find text-box in GridView using Javascript

I [am trying](https://answers.mindstick.com/qa/36834/which-two-programming-languages-should-i-master-in-if-i-am-trying-to-get-into-google-or-facebook) to get [access](https://www.mindstick.com/articles/12994/how-foreigners-can-access-blocked-websites-in-china) and find text-box in [GridView](https://www.mindstick.com/articles/873/update-delete-edit-gridview-in-asp-dot-net) using [javascript](https://www.mindstick.com/articles/874/how-to-create-watermark-text-for-textbox-by-using-javascript) but i am [getting an error](https://answers.mindstick.com/qa/95244/why-do-you-keep-getting-an-error-message-ox800ccc0b): 'The [name](https://yourviews.mindstick.com/view/87450/how-to-generate-a-brand-name-using-linkedin-comprehensive-guide) txt_UID' does not exist in the current [context](https://www.mindstick.com/forum/23245/what-is-context-in-android)'. Everything worked fine when my text-box was outside of the GridView. Here is my text-box in the gridview and my gridview is called GridView1:

```
 <asp:TemplateField ItemStyle-Width="150px" HeaderText="User Assigned">    <ItemTemplate>       <asp:TextBox ID="txt_UID" runat="server" Text='<%# Eval("UID")%>'        CssClass="AutoCompleteTextBox" Width="130px" BackColor="LightGoldenrodYellow"></asp:TextBox>       </ItemTemplate>         <ItemStyle Width="150px" />         </asp:TemplateField>
```

Here is my JavaScript:

```
  <script type ="text/javascript">        function setAutoComplete() {            var textBoxes = document.getElementsByClassName("AutoCompleteTextBox");            for (var i = 0; i < textBoxes.length; i++) {                addAutoComplete(textBoxes[i].id);            }        }</script> <script type="text/javascript">    function addAutoComplete(textBoxId) {        $("#" + textBoxId).autocomplete({            source: function (request, response) {                $.ajax({                    url: '<%=ResolveUrl("~/Service.asmx/GetUserNames") %>',                    data: "{ 'prefix': '" + request.term + "'}",                    dataType: "json",                    type: "POST",                    contentType: "application/json; charset=utf-8",                    success: function (data) {                        response($.map(data.d, function (item) {                            return {                                label: item.split('-')[0],                                val: item.split('-')[1]                            }                        }))                    },                    error: function (response) {                        alert(response.responseText);                    },                    failure: function (response) {                        alert(response.responseText);                    }                });            },            select: function (e, i) {                $("#<%=hfUserId.ClientID %>").val(i.item.val);            },            minLength: 1        });    }; <script type ="text/javascript">     $(document).ready(function () { setAutoComplete(); });    </script>
```

## Replies

### Reply by marcel ethan

you can use name attribute and the grid id to find it:

```
<asp:TextBox ID="txt_UID" name="mytextbox" runat="server" Text='<%#Eval("UID")%>'       
Width="130px" BackColor="LightGoldenrodYellow"></asp:TextBox>the javascript part: $("#<%=MyGrid.ClientID
%>[name=mytextbox]").autocomplete({});
```

### Reply by Anonymous User

Your Gridview will be rendered as Table and your control will be contained in cell of table. You can give a try to following.

```
<script type=”text/javascript”>$(document).ready(function(){tblTable=document.getElementById(‘<<Client ID of the GridView>>’);Cell=tblTable.rows[i].cells[j];//i and j are locations of that cell.FirstControl = Cell.childNodes[0];});</script>
```

replace <<Client ID of the GridView>> with id of your GridView


---

Original Source: https://www.mindstick.com/forum/12792/how-to-find-text-box-in-gridview-using-javascript

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
