 |
|
กำลังทดลองใช้ AutoComplete ค่ะ แต่ทำยังไงมันก็ไม่ยอมแสดงข้อมูลจากdatabase สักทีไม่รู้ทำตรงไหนผิด
ท่านผู้รู้คนไหนทราบช่วยชี้แจงด้วยนะคะ จะเป็นพระคุณอย่างสูงมากเพราะก่ะจะเอาไปใช้ใน project แล้วลองทำดูตามตัวอย่างที่หาๆมา สุดท้ายไม่ขึ้นอะไรเลย
ตอนนี้เขียน asp.net(c#) กับ mysql
ใครทราบก็ช่วยสงเคราะห์หน่อยนะคะ คือพอติดตรงนี้แล้วแบบวิ่งไปเขียนตัวอื่นสุดท้ายก็ติดที่เดิม ค้างมากค่ะ
ขอบคุณล่วงหน้าค่ะ ^ ^ ใครมีแนวทางดีๆกว่านี้ช่วยกรุณาชี้แนะด้วยนะคะ กะจะเอา AutoComplete ไปไว้ในgridview เพื่อ insert ข้อมูลค่ะ
Code (ASP)
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm4.aspx.cs" Inherits="WebApplication1.WebForm4" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></asp:ToolkitScriptManager>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:AutoCompleteExtender ID="TextBox1_AutoCompleteExtender" runat="server" DelimiterCharacters="" EnableCaching="False" Enabled="True" MinimumPrefixLength="1" ServiceMethod="GetCountryInfo" TargetControlID="TextBox1" ServicePath="~/AutoComplete.asmx">
</asp:AutoCompleteExtender>
</div>
</form>
</body>
</html>
Code (C#)
using System;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using MySql.Data.MySqlClient;
using System.Configuration;
///<summary>
/// Summary description for AutoComplete
///</summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX,
// uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class AutoComplete : System.Web.Services.WebService
{
public AutoComplete()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string[] GetCountryInfo(string prefixText)
{
int count = 0;
string sql = "Select CountryName from country Where CountryName like @prefixText";
MySqlDataAdapter da = new MySqlDataAdapter(sql,ConfigurationManager.ConnectionStrings["mydbConnectionString"].ConnectionString);
// da.SelectCommand.Parameters.Add("@prefixText", MySqlDbType.VarChar, 50).Value = prefixText+"%";
da.SelectCommand.Parameters.AddWithValue("@prefixText", string.Format("%{0}%", prefixText));
DataTable dt = new DataTable();
da.Fill(dt);
List<string> items = new List<string>(count);
for (int i = 0; i < dt.Columns.Count; i++)
{
items.Add(dt.Rows[i]["CountryName"].ToString());
}
return items.ToArray();
}
}
Tag : .NET, MySQL, Ajax, Web (ASP.NET), C#
|
|
 |
 |
 |
 |
Date :
2013-11-02 22:04:20 |
By :
payon |
View :
2155 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |