Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
3.67/5 (2 votes)
See more:
Hi,
I want to implement AutocompleteExtender into the textbox which is inside the datagrid.i have written webservice for that.
C#
<<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="smartsearch" %>
asp:DataGrid ID="dgProductList" Style="overflow: auto" runat="server" AllowPaging="True"
                                                                BorderWidth="0" CssClass="gridbody" CellSpacing="1" AutoGenerateColumns="False"
                                                                PageSize="5" CellPadding="0">
                                                                <ItemStyle CssClass="GridText"></ItemStyle>
                                                                <HeaderStyle CssClass="Gridheader"></HeaderStyle>
                                                                <Columns>
                                                                    <asp:BoundColumn DataField="mio_id" Visible="False"></asp:BoundColumn>
                                                                   <%-- <asp:BoundColumn DataField="Entity_ID" Visible="False"></asp:BoundColumn>--%>
                                                                   <asp:BoundColumn DataField="mio_category" Visible="False"></asp:BoundColumn>
                                                                    <asp:TemplateColumn HeaderStyle-VerticalAlign="Middle">
                                                                        <HeaderTemplate>
                                                                            <input type="checkbox" id="chkProductsListDeleteAll"  runat="server" name="chkTraceabilityDeleteAll">
                                                                        </HeaderTemplate>
                                                                        <ItemTemplate>
                                                                            <input type="checkbox" id="chkProductsListDelete"  runat="server" name="chkTraceabilityDelete">
                                                                        </ItemTemplate>
                                                                    </asp:TemplateColumn>
                                                                    <asp:ButtonColumn HeaderText="" ButtonType="LinkButton" Text="<img src='../../images/Edit.gif'  border=0/>"
                                                                        CommandName="Update" />
                                                                    
                                                                   
                                                                    <asp:TemplateColumn>
                                                                    <HeaderStyle HorizontalAlign="Center" />
                                                                        <HeaderTemplate>
                                                                            Category</HeaderTemplate>
                                                                        <ItemTemplate>
                                                                            <asp:DropDownList Width="350px" CssClass="dropdown" ID="drpCategory" runat="server">
                                                                            </asp:DropDownList>
                                                                        </ItemTemplate>
                                                                    </asp:TemplateColumn>
                                                                   
                                                                    <asp:TemplateColumn>
                                                                     <HeaderStyle HorizontalAlign="Center" />
                                                                        <HeaderTemplate>
                                                                            Products</HeaderTemplate>
                                                                        <ItemTemplate>
                                                                         <asp:TextBox ID="TxtProducts" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"mio_product")%>' AutoPostBack="true"  ></asp:TextBox>
                                                                         
                                                                         <smartsearch:AutoCompleteExtender  BehaviorID="AutoCompleteEx1" ID="productTextBox"  runat="server"
                                                            UseContextKey="true" Enabled="true" TargetControlID="TxtProducts" MinimumPrefixLength="1"
                                                            EnableCaching="true" ServiceMethod="GetProducts"  ServicePath="GetDataForSmartSearch.asmx" CompletionInterval="1000"
                                                            CompletionSetCount="20"   CompletionListItemCssClass="AutoCompleteExtender_CompletionListItem"                                                          
                                                            CompletionListHighlightedItemCssClass="AutoCompleteExtender_HighlightedItem" 
                                                            CompletionListCssClass="AutoCompleteExtender_CompletionList" DelimiterCharacters=";, :">
                                                            
                                                            <Animations>
                                                         <OnShow>
                                                   <Sequence>
                                               <OpacityAction Opacity="0" />
                                          <HideAction Visible="true" />   
                                    <ScriptAction Script="
                                         // Cache the size and setup the initial size
                                        var behavior = $find('AutoCompleteEx1');
                                        if (!behavior._height) {
                                           var target = behavior.get_completionList();
                                         behavior._height = target.offsetHeight - 2;
                                           target.style.height = '0px';
                                           }" />
                                
                                        <Parallel Duration=".4">
                                       <FadeIn />
                                <Length PropertyKey="height" StartValue="0" EndValueScript="$find('AutoCompleteEx1')._height" />
                            </Parallel>       
            </Sequence>      
          </OnShow>
      <OnHide>
         <%-- Collapse down to 0px and fade out --%>
                       <Parallel Duration=".4">
                            <FadeOut />
                            <Length PropertyKey="height" StartValueScript="$find('AutoCompleteEx1')._height" EndValue="0" />
                        </Parallel>
      </OnHide>
                                                            </Animations>
                                                        </smartsearch:AutoCompleteExtender>

                                                                            <%--<input type="text" style="width: 350px;"  önclick="GetPromt(this);" id="TxtProducts"
                                                                                class="textbox" name="TxtProducts"  runat="server" value='<%#DataBinder.Eval(Container.DataItem,"mio_product")%>'>--%>
                                                                        </ItemTemplate>
                                                                    </asp:TemplateColumn></Columns>
                                                                <PagerStyle Visible="False"></PagerStyle>
                                                            </asp:DataGrid>
                                                        </div>





While clciking on Add New row button, its giving this error--
Microsoft JScript runtime error: Sys.InvalidOperationException: Two components with the same id 'AutoCompleteEx1' can't be added to the application.

I want to use Ajax AutoCompleteExtender into the textbox which is in DataGrid

Webservice Code----------------

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class GetDataForSmartSearch : System.Web.Services.WebService
{

public GetDataForSmartSearch()
{

//Uncomment the following line if using designed components
//InitializeComponent();
}

[WebMethod]
[System.Web.Script.Services.ScriptMethod()]
// [System.Web.Services.WebMethod]

public string[] GetProducts(string PrefixTextForProducts, int count)
{
CController objGetProducts = new CController();
DataSet ds1 = new DataSet();
int i;
ds1 = objGetProducts.GetProductsData(PrefixTextForProducts);
List str = new List(ds1.Tables[0].Rows.Count);
//DataRow[] dr = ds
if (ds1.Tables[0].Rows.Count > 0)
{
for (i = 0; i < ds1.Tables[0].Rows.Count; i++)
{
str.Add(ds1.Tables[0].Rows[i]["mio_product"].ToString());
}
}
return str.ToArray();

}
Posted
Updated 5-Jan-14 18:40pm
v5

 
Share this answer
 
Comments
kamalsekhar 4-Jan-14 3:57am    
Hi Rakesh,
Its not working.please send me some other solution
Check out the document available on following link you will find example at last with description but this not with datagrid but you can use datagrid
https://docs.google.com/file/d/0B6KVMR-4BUaFaEVCZmpxVlhvLTA/edit[^]
 
Share this answer
 
Comments
kamalsekhar 4-Jan-14 9:03am    
Dear Vinay,
I am able to implement Ajax AutoCompleteExtender for separate textbox. but i want to implement this Ajax AutoCompleteExtender control into the textbox which is present inside the Datagrid . please send me solution.
Vinay Jade 4-Jan-14 9:50am    
ok i'll try first and then only i can send solution...
bt i wanted to know one thing, you are developing this app for web or desktop?
kamalsekhar 5-Jan-14 1:53am    
I am developing application for Web Application and here one more thing i would like to tell, in my application, while click on Add Button, two column is generating dynamically in the datagrid and i m calling webservice also. kindly send me the solution ASAP.its urgent for me..please..
Vinay Jade 5-Jan-14 3:48am    
ok i will try with normal grid
kamalsekhar 6-Jan-14 0:19am    
ok.This is my webservice code for fetching the data from database.

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class GetDataForSmartSearch : System.Web.Services.WebService
{

public GetDataForSmartSearch()
{

//Uncomment the following line if using designed components
//InitializeComponent();
}

[WebMethod]
[System.Web.Script.Services.ScriptMethod()]
// [System.Web.Services.WebMethod]
// Added by kamal for getting products on 3-Jan-2013
public string[] GetProducts(string PrefixTextForProducts, int count)
{
CController objGetProducts = new CController();
DataSet ds1 = new DataSet();
int i;
ds1 = objGetProducts.GetProductsData(PrefixTextForProducts);
List<string> str = new List<string>(ds1.Tables[0].Rows.Count);
//DataRow[] dr = ds
if (ds1.Tables[0].Rows.Count > 0)
{
for (i = 0; i < ds1.Tables[0].Rows.Count; i++)
{
str.Add(ds1.Tables[0].Rows[i]["mio_product"].ToString());
}
}
return str.ToArray();

}

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