2009-01-31 53 views
1

我使用AutoCompleteExtenderAjax控件工具包,它是stragely行爲。Ajax控件工具包AutoCompleteExtender剝離零和未來與幻象值

我的服務方法如下所示:

[System.Web.Services.WebMethod] 
[System.Web.Script.Services.ScriptMethod] 
public string[] getEJMaps(string prefixText, int count) 
{ // method that returns the auto-suggest for the EJMaps positions 
    string file_location = HttpContext.Current.Server.MapPath("~") + Utils.Settings.Get("attachments") + "ejmaps\\ejmaps.xml"; 
    XElement x = XElement.Load(file_location); 
    string[] positions = (from p in x.Descendants("position") where p.Value.StartsWith(prefixText) orderby p.Value select p.Value).ToArray(); 
    if (positions.Count() == 0) 
     return new string[] { "No Matching Results" }; 
    else return positions; 
} 

,它工作正常,如果我的價值觀調用它的測試頁getEJMaps(「00056」,4)我得到這些結果:

00056399 
00056717 
00056721 
00056722 
00056900 
... 

這就是我想要的東西,但是當我把它綁在文本框和類型在00056,我得到的結果:

56399 
24015 
24017 
56717 
56721 
... 

這說明兩個問題:

  1. 到底發生到我的零是什麼?我怎樣才能讓他們回來?
  2. 這些「240xx」數字來自哪裏?甚至在xml文檔中都沒有這些值!

我完全被這個難住了,請幫我:)

回答

2

你需要用引號括陣列中的每個字符串。例如,getEJMaps應該返回一個數組,看起來像:

"00056399" 
"00056717" 
"00056721" 
"00056722" 
"00056900" 
... 

不要忘記,你需要逃避與\

引號如果這能解決丟失0的,但不是幻象值,讓我知道,我會盡力協助。我想它會。

+0

他們都串 - 這是奇怪的一部分; 我放棄了工具包,並用jQuery代替http://naspinski.net/post/Using-jqueryautosuggestjs-with-AspNet.aspx – naspinski 2009-02-04 06:11:15

1
SELECT 
'''' + CustomerShipTo + '''' AS CustomerShipTo 

FROM dbo.CustomerMaster 

這應該工作..... 它爲我