第壹步,創建webservice
using System;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// 若要允許使用 ASP.NET AJAX 從腳本中調用此 Web 服務,請取消對下行的註釋。
// [System.Web.Script.Services.ScriptService]
public class Service : System.Web.Services.WebService
{
public Service()
{
//如果使用設計的組件,請取消註釋以下行
//InitializeComponent();
}
[WebMethod]
public string[] HelloWorld(string ss)
{
//查詢相關信息放入數組
return 數組;
}
}
第二步,要使用textbox,則需ListBox的支持,具體操作:
在textbox下方有壹個隱藏的ListBox,當在textbox輸入值時,調用服務返回值要在Listbox中顯示,同時要ListBox顯示.
第三步,在TextBox的TextChanged事件裏做提示:
private void textBox1_TextChanged(object sender, EventArgs e)
{
//調用webservice
//返回結果添加到ListBox
//ListBox.Visible = true;
}
第四步,在listbox項選擇事件裏添加:
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
textBox1.Text = listBox1.SelectedItem.ToString();
listBox1.Visible = false;
}