Click here to Skip to main content
15,905,679 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

I have an gridview with five textboxes. Inside the first textbox while i Pressing the Key it should retrieve list of strings from database and shown to the User. I used JQuery for do that.

My JQuery Script is..

<pre lang="xml"><script type="text/javascript">
    $(document).ready(function() {
        $("#<%= txt_grd_ProdName.ClientID %>").autocomplete('PurchaseHandler.ashx');
    });
</script>



This above code works fine when i made textbox outside the grid. But while i tried it inside grid it shows error like
"The name 'txt_grd_ProdName' does not exist in the current context"

I think My Grid textbox is not reacheable to my JQuery. Please help me out.


For your info,
I used MasterPage and Content Page...

My design page code is...
<pre lang="xml"><asp:TemplateField HeaderText="Products">
                 <ItemTemplate>
                      <asp:TextBox ID="txt_grd_ProdName" Width="75px" runat="server" ontextchanged="txt_grd_ProdName_TextChanged" AutoPostBack="True"
                          CausesValidation="True"></asp:TextBox>
                  </ItemTemplate>
                <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                  </asp:TemplateField>


Posted
Updated 1-Jul-11 22:47pm
v2

A workaround is to define a special css class for this textbox and using it like selector with jQuery

in code aspx code
<asp:Textbox ID=myTextBox" runat="server"  CssClass = "AutoCompleteTxtBx" />


in js
$('.AutoCompleteTxtBx').autocomplete('PurchaseHandler.ashx');


In this case, all "duplicated" textbox in your gridview have autocompletion.
 
Share this answer
 
v2
Comments
J.Karthick 2-Jul-11 5:11am    
Thanks a lot............ Its works fineeeeeeee :D :D

Cheeeers....
Masterpages, grids, etc should not matter on the client side. However, if you have a textbox inside each row of a grid, then I am surprised this compiles, as txt_grd_ProdName, if it's a textbox inside a template, has no visibility to your code, as there's not one textbox, but many of them. So, you need a mechanism to store and retrieve the textbox in your selected row as well as knowing which row it is. The best way to do this, is to pass the textbox through your event handler on the textbox, by passing 'this' as an argument.
 
Share this answer
 
Comments
J.Karthick 2-Jul-11 4:36am    
Where should i pass 'this' argument ??
Can you please give some code samples??
or
can you explain it brief?
Christian Graus 2-Jul-11 4:57am    
Exactly as I said. Your event handler, in your textbox, like onblur=xxx becomes onblur="blurred(this);" where the function blurred takes a parameter, and will be passed the textbox that sent it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900