2

アイテムのコレクションを返すサービス メソッドに追加情報を渡すにはどうすればよいですか? フォームに 2 つのテキスト ボックスがあり、データベース内の特定のアカウント ID に基づいて名前を入力する必要があります。そのため、整数を getNamesForDropDown メソッドに渡す必要があります。何をすべきかわからなかったので、間違ったことをしてしまい、CompletionSetCount を使用して実際に必要な情報を渡しました。

[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public string[] getNamesForDropDown(string prefixText, int count) 
{
   String sql = "Select fldName From idAccountReps Where idAccount = " + count.ToString();
   //... rest of the method removed, this should be enough code to understand
   //... the evil wrongness I did. 
}

フロントサイドのaspxファイルで、ユーザーが現在そのページで表示しているアカウントIDに基づいてCompletionSetCountを設定しました。

<ajaxtk:AutoCompleteExtender 
    runat="server" 
    ID="AC1" 
    TargetControlID="txtAccName"
    ServiceMethod="getNamesForDropDown"
    ServicePath="AccountInfo.asmx"
    MinimumPrefixLength="1" 
    EnableCaching="true"
    CompletionSetCount='<%# Eval("idAccount") %>'
/>

だから、それは間違いなく間違った方法です.正しい方法は何ですか?

4

4 に答える 4

5

azam has the right idea- but the signature of the autocomplete method can also have a third parameter:

public string[] yourmethod(string prefixText, int count, string contextKey)

you can Split up the results of the contextKey string using Azam's method- but this way you do not have to worry about sanatizing the user's input of the .Split()'s delimiter (:)

于 2008-10-09T19:53:54.187 に答える
3

Holy smoke, I think this is what I need, I swear I never saw this option before I started programming this. Is this a new property to the autocompleteextender?

Excerpt from Documentation:

ContextKey - User/page specific context provided to an optional overload of the web method described by ServiceMethod/ServicePath. If the context key is used, it should have the same signature with an additional parameter named contextKey of type string:

[System.Web.Services.WebMethod] [System.Web.Script.Services.ScriptMethod] public string[] GetCompletionList( string prefixText, int count, string contextKey) { ... }

Note that you can replace "GetCompletionList" with a name of your choice, but the return type and parameter name and type must exactly match, including case.

Edit: It doesn't matter if it is new or not, or whether i just completely overlooked it. It works, and I'm happy. It took me about 10 minutes from being confused to figuring out my own answer.

于 2008-10-09T19:52:51.647 に答える
2

必要に応じて、prefixText で区切り記号を使用できます。したがって、「1:bcd」を渡すことができ、サービス側で 2 つの項目を分割できます。

string[] arguments = prefixText.Split(':'); 
int id = Int32.Parse(arguments[0]);
string text = arguments[1]; 
于 2008-10-09T19:48:25.430 に答える