こんにちは、検索基準に基づいてテキストボックスにデータを入力しました。つまり、a を入力すると、a で始まるアイテムがテキストボックスに入力され、別のテキストボックスを使用してパーティー名を表示しましたが、アイテムのテキストボックスで値を選択すると問題が発生します。テキストボックスに表示されていませんが、パーティー名のテキストボックスは機能しています。つまり、ドロップダウンからパーティー名を選択すると、非表示のフィールドとテキストボックスに表示されますが、アイテムの場合、jquery関数を送信して機能していないので、助けてください
$(document).ready(function() {
SearchText();
SearchItem();
});
function SearchText() {
$('input[name$="tbAuto"]').autocomplete({
source: function(request, response) {
$.ajax({
url: "PartyList.asmx/FetchPartyList",
data: "{ 'prefix': '" + request.term + "' }",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function(data) {
response(data.d);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
}
});
},
minLength: 1,
focus: function(event, ui) {
$('input[name$="tbAuto"]').val(ui.item.Name);
return false;
},
select: function(event, ui) {
$('input[name$="tbAuto"]').val(ui.item.Name);
$('input[name$="tbHidden"]').val(ui.item.value);
return false;
}
}).data('autocomplete')._renderItem = function(ul, item) {
return $('<li>').data('item.autocomplete', item).append('<a>' + item.Name + '</a>').appendTo(ul);
};
}
function SearchItem() {
$('input[name$="txtitem"]').autocomplete({
source: function(request, response) {
$.ajax({
url: "Itemslist.asmx/FetchItemList",
data: "{ 'prefix': '" + request.term + "' }",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function(data) {
response(data.d);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
}
});
},
minLength: 1,
focus: function(event, ui) {
$('input[name$="txtitem"]').val(ui.item1.Name);
return false;
},
select: function(event, ui) {
$('input[name$="txtitem"]').val(ui.item1.Name);
$('input[name$="hditem"]').val(ui.item1.value);
return false;
}
}).data('autocomplete')._renderItem = function(ul, item1) {
return $('<li>').data('item1.autocomplete', item1).append('<a>' + item1.Name + '</a>').appendTo(ul);
};
}
ItemInfo クラス:
public class Iteminfo
{
connection oConnection = new connection();
Control oControl = new Control();
AccountInfo oAccount = new AccountInfo();
connection c = new connection();
public string Title { get; set; }
public string Name { get; set; }
public string value { get; set; }
public List<Iteminfo> GetItems(string prefixText)
{
List<Iteminfo> itemList = new List<Iteminfo>();
try
{
DataTable dt;
AccountInfo oAccount = new AccountInfo();
//dt = oAccount.GetAccountInfo((int)HttpContext.Current.Session["CompCode"], 0);
dt = oAccount.GetIteminfo(prefixText);
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
itemList.Add(new Iteminfo() { Name = dt.Rows[i]["groupname"].ToString() + dt.Rows[i]["subgroup"].ToString() + dt.Rows[i]["itemname"], Title = dt.Rows[i]["itemname"].ToString(),
value = dt.Rows[i]["groupname"].ToString() + dt.Rows[i]["subgroup"].ToString() + dt.Rows[i]["itemname"].ToString()+";"+dt.Rows[i]["itemcode"].ToString() });
}
}
}
catch (SqlException)
{
itemList.Add(new Iteminfo() { Name = "Problem Getting Results.", value = "Error" });
}
if (itemList.Count == 0)
itemList.Add(new Iteminfo() { Name = "Nothing to Display.", value = "Info" });
return itemList;
}
}
ページ方式:
[WebMethod]
public List<Iteminfo> FetchItemList(string prefix)
{
var items = new Iteminfo();
var fetchitems = items.GetItems(prefix);
//.Where(m => m.Name.ToLower().StartsWith(prefix.ToLower()));
// .Where(m => m.Name.ToLower().StartsWith(prefix.ToLower()));
return fetchitems.ToList();
}