Click here to Skip to main content
15,562,816 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
I want to apply autocomplete in gridview (in asp.net3.5 with C#) using jquery and this gridview is within the ajax
XML
<update id=""UpdatePanel1"" runat=""server"><br" mode="hold" />    <ContentTemplate>.

For this i am using method within the <ItemTemplate>
C#
$(document).ready(function(){
    $('[id$=txtItemCode]').autocomplete("SearchItem.aspx").result(function (event, data, formatted) {
        if (data) {
            alert('Value: '+ data[1]);
        }
        else {
            $('[id$=txtItemID]').val('-1');
        }
    });
    });

since in gridview the textbox id is
XML
<asp:TextBox id="txtItemCode" />
but
on browser such as
XML
<input type="textbox" id="ctl00_otherName_101txtItemCode" />

and then for the next row same textbox id is now
XML
 <input type="textbox" id="ctl00_otherName_102txtItemCode" />
i tried
1. put this code within the <ItemTemplate>
2. <%= txtItemCode.ClientID %>
3. $("*[@id$=theGridId] input[@id$=txtItemCode]")
4. jQuery.expr[':'].asp = function(elem, i, match) {
    return (elem.id && elem.id.match(match[3] + "$"));
};
and $(":asp(txtItemCode)").autocomplete...
5.$('.txtItemCode').autocomplete("LookupCodes.aspx?type=IC", { mustMatch: true })

but autocomplete does not work in all the cases
plz help me.
Posted
Updated 2-Feb-11 20:24pm
v2
Comments
Sunasara Imdadhusen 3-Feb-11 1:24am    
Added code formatting

1 solution

hi,

one probable solve of this problem is using a dummy class and then use that as reference for jquery instead of textbox's id. This way rendered id will not be an issue for auto complete. Use this code for textbox's inside <itemtemplate></itemtemplate>
<asp:TextBox id="txtItemCode" CssClass="dummyDataBinder" />


then reference using class name

C#
$(document).ready(function()
{
    $('.dummyDataBinder')
    .autocomplete("SearchItem.aspx")
    .result(function (event, data, formatted)
    {
            if (data)
        {
                    alert('Value: '+ data[1]);
            }
            else
        {
                    $('.dummyDataBinder').val('-1');
            }
        });
});
 
Share this answer
 

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