0
我使用AJAX自動完成擴展使用服務器代碼加載所有國家的所有城市..阿賈克斯自動完成擴展拋出錯誤
一切正常.. 如果我點擊「封殺」,一組結果會增加.. 第一名將是班加羅爾,第二名將是bangkog等。 的事情是,如果我按下鍵瀏覽通過bangkog和其他人,它會引發錯誤。
的Javascript運行時錯誤:
jaascript runtime error:System.argumentnullexception:value cannot be null.parameter name :classname in ajax autocomplete extender
ASPX
<autofill:AutoCompleteExtender BehaviorID="AutoCompleteEx" ServiceMethod="GetCompletionList"
ID="fromlocation_AutoCompleteExtender" runat="server" DelimiterCharacters=""
Enabled="True" ServicePath="" TargetControlID="fromlocation" UseContextKey="True"
MinimumPrefixLength="2" CompletionInterval="10" EnableCaching="true" CompletionSetCount="20"
CompletionListItemCssClass="autocomplete_listItem">
<Animations>
<OnShow>
<Sequence>
<OpacityAction Opacity="0" />
<HideAction Visible="true" />
<ScriptAction Script="
// Cache the size and setup the initial size
var behavior = $find('AutoCompleteEx');
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('AutoCompleteEx')._height" />
</Parallel>
</Sequence>
</OnShow>
<OnHide>
<Parallel Duration=".4">
<FadeOut />
<Length PropertyKey="height" StartValueScript="$find('AutoCompleteEx')._height" EndValue="0" />
</Parallel>
</OnHide>
</Animations>
</autofill:AutoCompleteExtender>
C#
[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
public static string[] GetCompletionList(string prefixText, int count, string contextKey)
{
SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["connstring"].ToString());
//SqlCommand cmd = new SqlCommand("SELECT Code,City FROM CCode WHERE City LIKE '" + prefixText + "%'", conn);
SqlCommand cmd = new SqlCommand("SELECT coalesce(Code + ', ', '') + City as codes FROM CCode WHERE City LIKE '" + prefixText + "%'", conn);
SqlDataReader oReader;
conn.Open();
List<string> CompletionSet = new List<string>();
oReader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
while (oReader.Read())
CompletionSet.Add(oReader["codes"].ToString());
return CompletionSet.ToArray();
}
你需要多花ecify'CompletionListHighlightedItemCssClass' css – Damith