我正在使用ajax autocomplete extender使用服务器代码加载所有国家/地区的所有城市..
一切都很好.. 如果我点击“禁止”,将添加一组结果.. 第一名将是班加罗尔,第二名将是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();
}
答案 0 :(得分:0)
以上的解决方案在另一个论坛中列出..我发现通过谷歌搜索..
在上面的代码中我只添加了
CompletionListItemCssClass="autocomplete_listItem"
但是在那个论坛上,他们已经提到定义下面的代码..
CompletionListHighlightedItemCssClass="two"
我做到了,现在问题解决了。