Hi all,
i have one gridview in it's item template i have taken textbox named as txtProjectName,and i want to make it as auto complete textbox, below is what ia have done. :-
asp:GridView ID="gvDetails" runat="server" AutoGenerateColumns="False"
OnRowDataBound="gvDetails_RowDataBound" CssClass="GridViewStyle">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:Label ID="Label3" runat="server" Text="Machine No"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblMachineNo" runat="server"></asp:Label>
<asp:Label ID="lblMachineId" Text='<%#Eval("AssetId") %>' Visible="false" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
<asp:Label ID="Label7" runat="server" Text="Sr. No."></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblSrNo" Text='<%#Eval("SrNo") %>' runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
<asp:Label ID="Label4" runat="server" Text="Brand"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblBrand" runat="server"></asp:Label>
<asp:Label ID="lblBrandId" Text='<%#Eval("Brand") %>' Visible="false" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
<asp:Label ID="lblFi" runat="server" Text="Field off"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:DropDownList ID="ddlFieldoff" runat="server">
</asp:DropDownList>
<asp:Label ID="lblFieldId" Text='<%#Eval("Location") %>' runat="server" Visible="False"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
<asp:Label ID="Label5" runat="server" Text="Dispatch Date"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:TextBox ID="txtDispatchDate" runat="server" Width="80px"></asp:TextBox><asp:CalendarExtender
ID="txtDispatchDate_CalendarExtender" runat="server" Enabled="True"
Format="dd/MM/yyyy" TargetControlID="txtDispatchDate">
</asp:CalendarExtender>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
<asp:Label ID="Label6" runat="server" Text="Project Name"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:TextBox ID="txtProjectName" runat="server"></asp:TextBox>
<asp:AutoCompleteExtender ID="txtProjectName_AutoCompleteExtender"
runat="server" CompletionListCssClass="autocomplete_completionListElement"
CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem"
CompletionListItemCssClass="autocomplete_listItem" DelimiterCharacters=""
Enabled="True" MinimumPrefixLength="1" ServiceMethod="GetProjectNames"
ServicePath="~/LMSWebService.asmx" TargetControlID="txtProjectName"
CompletionInterval="10" CompletionSetCount="12">
</asp:AutoCompleteExtender>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
<asp:Button ID="btnAllot" runat="server" Text="Allot" CssClass="SaveButton" OnClick="btnAllot_Click" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chbxAllot" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<HeaderStyle CssClass="GridHeaderStyle" />
</asp:GridView>
below is the 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 LMSWebService : System.Web.Services.WebService {
public LMSWebService () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string HelloWorld() {
return "Hello World";
}
[WebMethod]
[System.Web.Script.Services.ScriptMethod]
public List<string> GetProjectNames(string strPrefix)
{
List<string> result = new List<string>();
using (OleDbConnection conole = new OleDbConnection(@"Provider=Microsoft.JET.OlEDB.4.0;" + @"Data Source=" + Server.MapPath("App_Data/Data/fors.mdb") + ""))
{
using (OleDbCommand cmdole = new OleDbCommand("SELECT Distinct JobNo,JobName from master where closeStatus<>'c' and JobName Like '*"+ strPrefix +"*'", conole))
{
conole.Open();
OleDbDataReader oldr = cmdole.ExecuteReader();
while (oldr.Read() == true)
{
result.Add(oldr[1].ToString());
}
oldr.Dispose();
cmdole.Dispose();
conole.Close();
return result;
}
}
}
}
.but its not working ...
i have written in the grid row databound also..as below :-
TextBox txtProjects = ((TextBox)e.Row.FindControl("txtProjectName"));
AjaxControlToolkit.AutoCompleteExtender AutoCompelte1 = ((AjaxControlToolkit.AutoCompleteExtender)e.Row.FindControl("txtProjectName_AutoCompleteExtender"));
AutoCompelte1.TargetControlID = txtProjects.ID;
please help i am not getting the solution ..