我们如何使用asp.net,webservie和SQL数据库集成自动完成的jQuery [英] how can we integrate jquery autocomplete using asp.net, webservie and sql database

查看:168
本文介绍了我们如何使用asp.net,webservie和SQL数据库集成自动完成的jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我想实现的自动完成的jQuery和ASP.NET给出的code
但不能因为你使用的是亚音速查询数据库,以便您能告诉我如何查询sqldatabase和web服务在asp.net中使用C#查询结果绑定到插件整合它。请其紧迫。

hi i am trying to implement the code given for "jQuery Autocomplete and ASP.NET" but unable to integrate it cause you are using subsonic to query database so can you tell me how to query sqldatabase and bind the query result to the plugin from webservice in asp.net using C#. please its urgent.

推荐答案

这是一个pretty容易的事,美中不足的是,jQuery的自动完成扩展预期值数组。下面是例子我如何解析从ASMX网页serivce标准的XML结果与jQuery的自动完成扩展使用。

This is a pretty easy task, the catch is that the jQuery autocomplete extender expects an array of values. Here is example of how I parse the standard XML results from a ASMX web serivce to use with the jQuery autocomplete extender.

由于ASP.NET喜欢重写你的ID,可以在客户端ID传递到获得动态ID。

Since ASP.NET likes to rewrite your ID's, you can pass in the ClientID to get the dynamic ID.

    $("#<%= TextBox1.ClientID %>").autocomplete("/Demo/WebSvc.asmx/SuggestCustomers", {
        parse: function(data) {
            var parsed = [];

            $(data).find("string").each(function() {
                parsed[parsed.length] = {
                    data: [$(this).text()],
                    value: $(this).text(),
                    result: [$(this).text()]
                };
            });
            return parsed;
        },
        dataType: "xml"
    });

下面是相关的网络服务将是什么样子,记得注释对Web服务的[ScriptService]属性:

Here is what the associated web service would look like, remember to uncomment the [ScriptService] attribute on the web service:

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class WebSvc: WebService
{
    [WebMethod]
    public string[] SuggestedCustomers(string q)
    {
        // Do Query

		// Add items into string array
        List<string> items = new List<string>();
        while (dr.Read())
        {
            items.Add(dr[0].ToString());
        }

		// Return array
        return items.ToArray();
    }

}

这篇关于我们如何使用asp.net,webservie和SQL数据库集成自动完成的jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆