In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is about how to implement the asp.net+ajax+sqlserver auto-completion function. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Description: the database connection string is in the web.config file, and the official Northwind database is used for convenience.
Reference (salute to its author):
Http://www.loveweb8.com/plus/demo.php?aid=57 this example is the html source code. The automatic completion function is realized by using jquery.autocomplete plug-in and js. Because my need is to combine the sqlserver database table to achieve automatic completion function. The next step is to convert the database table to an js array, and it's natural to think of ajax.
The second part of this article on the two basic development modes of Asp.NetAjax is an example of js calling webservice.
Code parsing.
1. Add a webservice file.
Add a new item, "WCF Service with AJAX enabled", and name the new file DBService.svc.
two。 Add a function to DBService.svc, and the return value of the function is the data that is prompted to complete automatically.
The code is as follows:
[OperationContract]
Public string getSortList ()
{
List sorts = new List ()
Using (SqlConnection cn = new SqlConnection (ConfigurationManager.ConnectionStrings ["zhui.pc"] .ConnectionString))
{
Cn.Open ()
SqlCommand cmd = new SqlCommand ("select [LastName] from [dbo]. [Employees]", cn)
DataTable dt = new DataTable ()
Using (SqlDataAdapter da = new SqlDataAdapter (cmd))
{
Da.Fill (dt)
}
Foreach (DataRow row in dt.Rows)
{
Sorts.Add (row [0] .ToString ())
}
Cn.Close ()
}
Return string.Join ("," sorts.ToArray ())
}
3. Add js and css files to the default.aspx file:
The code is as follows:
4. Call webservice in the $() .ready (function ()) function in the head section of default.aspx to get the automatically completed data and associate the data to the input box.
The code is as follows:
Ready (function () {)
NewsSort.getSortList (OnComplete, OnFailed, null)
Function OnComplete (args, context) {
('# MainContent_searchBox') .AutoComplete ({
'data': args.split (",")
'itemHeight': 20
'listDirection': 'down'
'width': 280,
}). AutoComplete ('show')
}
Function OnFailed (args) {
Alert ("error!")
}
});
Thank you for reading! This is the end of the article on "how to achieve the automatic completion of asp.net+ajax+sqlserver". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.