I have added autocomplete extender to a text box. I am using a Query in the Webservice to fetch 'names' from the database.
the CompletionList displays the names right, but the end adds a 'null' at the end of the list.
i have executed the query separately (in sql managment studio) and it does not return a 'null' . I have also run the webservice, entered the values and 'null' is not returned as a result.
</ContentTemplate>
</atlas:UpdatePanel> <%-- End of UpdPanCustName --%>
'====================WEB SERVICE=====================
'===== To fetch the "Report To"
<WebMethod()> _
Public Function GetReportToNames(ByVal prefixText As String, ByVal contextKey As String) As String()
Dim sql As String = "" 'To store sql query
sql = "Select Distinct OnCallTripDtls.ReportTo from OnCallTrip LEFT OUTER JOIN OnCallTripDtls ON OnCallTrip.Id=OnCallTripDtls.OnCallTripId Where OnCallTripDtls.ReportTo<>'' AND OnCallTrip.CustName = @contextKey AND OnCallTripDtls.ReportTo LIKE @prefixText"
'Execute the query and store the fetched value in the items array and return it
Dim da As SqlDataAdapter
Dim dt As DataTable
da = New SqlDataAdapter(sql, strConn)
da.SelectCommand.Parameters.Add("@contextKey", SqlDbType.VarChar, 50).Value = contextKey
da.SelectCommand.Parameters.Add("@prefixText", SqlDbType.VarChar, 50).Value = prefixText + "%"
dt = New DataTable()
da.Fill(dt)
Dim items(dt.Rows.Count) As String
Dim i As Integer = 0
Dim dr As DataRow
For Each dr In dt.Rows
items.SetValue(dr(0).ToString(), i)
i = i + 1
Next
Return items
End Function
<WebMethod()> _
Public Function GetReportToNames(ByVal prefixText As String, ByVal contextKey As String) As String()
To
<WebMethod()> _
<Script.Services.ScriptMethod()> _
Public Shared Function GetReportToNames(ByVal prefixText As String, ByVal contextKey As String) As String()
And make sure your class in your webservice has this:
Public Class myClass
Inherits System.Web.Services.WebService
See if that works. It may just be the Script.Services.ScriptMethod, however, I always make my autocomplete methods shared as I use them in them in the same page rather than an asmx file.
sara_23apr
Member
70 Points
112 Posts
AutoCompleteExtender displays a 'null' at the end of the list
Jul 03, 2008 10:54 AM|LINK
Hello Friends
I have added autocomplete extender to a text box. I am using a Query in the Webservice to fetch 'names' from the database.
the CompletionList displays the names right, but the end adds a 'null' at the end of the list.
i have executed the query separately (in sql managment studio) and it does not return a 'null' . I have also run the webservice, entered the values and 'null' is not returned as a result.
Please Help
Sara
tompy_nation
Contributor
5054 Points
1268 Posts
Re: AutoCompleteExtender displays a 'null' at the end of the list
Jul 03, 2008 11:30 AM|LINK
Did you set a completion list count which is greater then the number of results returned?
sara_23apr
Member
70 Points
112 Posts
Re: AutoCompleteExtender displays a 'null' at the end of the list
Jul 03, 2008 10:59 PM|LINK
Thanks for the reply . I have not set completion list count .
This is how i have used the extender
<ajaxToolkit:AutoCompleteExtender
id="AutoComplte1"
CompletionListItemCssClass="autocomplete_listItem"
CompletionListCssClass="autocomplete_completionListElement"
CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem"
runat="server"
MinimumPrefixLength=0
ServiceMethod="GetReportTo"
ServicePath="WebServce4Ajax.asmx"
TargetControlID="txtReportTo"
UseContextKey="true"
ContextKey="Country" >
sara_23apr
Member
70 Points
112 Posts
Re: AutoCompleteExtender displays a 'null' at the end of the list
Jul 07, 2008 09:38 AM|LINK
still struggling with the problem. Can somebody help ?
Sara
TCavins
Member
718 Points
213 Posts
Re: AutoCompleteExtender displays a 'null' at the end of the list
Jul 07, 2008 01:04 PM|LINK
Please post your ServiceMethod that retrieves the list of values.
Verify that it is returning an array and not a string.
Tim
sara_23apr
Member
70 Points
112 Posts
Re: AutoCompleteExtender displays a 'null' at the end of the list
Jul 08, 2008 07:35 AM|LINK
<atlas:UpdatePanel ID="UpdPanCustName" UpdateMode=Conditional runat="Server">
<ContentTemplate>
<cc1:keysortdropdownlist id="ddlCustomer" TabIndex="16" Style="top: 68px; z-index: 150;" CssClass="ThreeColDDLA" BackColor="LightYellow" runat="server" AutoPostBack=true ></cc1:keysortdropdownlist>
<asp:TextBox ID="txtReportTo" TabIndex="28" Style="top:128px; z-index: 161;" CssClass="ThreeColTxtBoxB" MaxLength="50" runat="server" AutoPostBack=true></asp:TextBox>
<ajaxToolkit:AutoCompleteExtender id="AutoComplteReportToNames" CompletionListItemCssClass="autocomplete_listItem" CompletionListCssClass="autocomplete_completionListElement" CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem" runat="server" MinimumPrefixLength=1 ServiceMethod="GetReportToNames" ServicePath="Data4AutoExtender.asmx" TargetControlID="txtReportTo" UseContextKey="true" ContextKey="Country" EnableCaching=false ></ajaxToolkit:AutoCompleteExtender>
</ContentTemplate>
</atlas:UpdatePanel> <%-- End of UpdPanCustName --%>
'====================WEB SERVICE=====================
'===== To fetch the "Report To"
<WebMethod()> _
Public Function GetReportToNames(ByVal prefixText As String, ByVal contextKey As String) As String()
Dim sql As String = "" 'To store sql query
sql = "Select Distinct OnCallTripDtls.ReportTo from OnCallTrip LEFT OUTER JOIN OnCallTripDtls ON OnCallTrip.Id=OnCallTripDtls.OnCallTripId Where OnCallTripDtls.ReportTo<>'' AND OnCallTrip.CustName = @contextKey AND OnCallTripDtls.ReportTo LIKE @prefixText"
'Execute the query and store the fetched value in the items array and return it
Dim da As SqlDataAdapter
Dim dt As DataTable
da = New SqlDataAdapter(sql, strConn)
da.SelectCommand.Parameters.Add("@contextKey", SqlDbType.VarChar, 50).Value = contextKey
da.SelectCommand.Parameters.Add("@prefixText", SqlDbType.VarChar, 50).Value = prefixText + "%"
dt = New DataTable()
da.Fill(dt)
Dim items(dt.Rows.Count) As String
Dim i As Integer = 0
Dim dr As DataRow
For Each dr In dt.Rows
items.SetValue(dr(0).ToString(), i)
i = i + 1
Next
Return items
End Function
sara_23apr
Member
70 Points
112 Posts
Re: AutoCompleteExtender displays a 'null' at the end of the list
Jul 08, 2008 07:37 AM|LINK
Tim Thanks for the reply. I have posted the code. Kindly take a look.TCavins
Member
718 Points
213 Posts
Re: AutoCompleteExtender displays a 'null' at the end of the list
Jul 08, 2008 01:25 PM|LINK
Add/Change the following:
<WebMethod()> _
Public Function GetReportToNames(ByVal prefixText As String, ByVal contextKey As String) As String()
To
<WebMethod()> _
<Script.Services.ScriptMethod()> _
Public Shared Function GetReportToNames(ByVal prefixText As String, ByVal contextKey As String) As String()
And make sure your class in your webservice has this:
<WebService(Namespace:="YourUrl")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<System.Web.Script.Services.ScriptService()> _
Public Class myClass
Inherits System.Web.Services.WebService
See if that works. It may just be the Script.Services.ScriptMethod, however, I always make my autocomplete methods shared as I use them in them in the same page rather than an asmx file.
Tim
TCavins
Member
718 Points
213 Posts
Re: AutoCompleteExtender displays a 'null' at the end of the list
Jul 08, 2008 01:38 PM|LINK
Also try putting quotes around items.SetValue(dr(0).ToString(), i)
items.SetValue("""" & dr(0).ToString() & """", i)
TCavins
Member
718 Points
213 Posts
Re: AutoCompleteExtender displays a 'null' at the end of the list
Jul 08, 2008 03:26 PM|LINK
Sara,
Without including the null value, does the sql statement when run seperately return the same number of results that are in your drop down extender?
It could be as simple as a something in your data throwing the whole thing off.
What version of the toolkit are you using?
Tim