Asp.net WebForm中用于文本框的AJAX自动完成扩展器.(如何将.Net-WebService链接到AJAX自动完成扩展器!) [英] AJAX Auto Complete Extender for textbox in Asp.net webForm.(How to Link .Net-WebService to a AJAX Auto complete Extender! )

查看:83
本文介绍了Asp.net WebForm中用于文本框的AJAX自动完成扩展器.(如何将.Net-WebService链接到AJAX自动完成扩展器!)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好
我对asp.net中的Web服务是陌生的.基本上在我的asp.net解决方案中,它有3个基本项目,即(PAL(所有Web表单接口都在其中),BAL(参考业务逻辑)和DAL(参考数据访问-SQL服务器部分).PAL链接到BAL然后将BAL链接到DAL,然后我想向位于PAL的Web窗体中的文本框添加Ajax自动完成扩展器,只需说一下testwebform.aspx,然后在BAL中编写一个webService,即webService1并按如下所示添加一个webmethod. .


Hi everyone
i''m new to web services in asp.net. well basically in my asp.net Solution ,it has 3 basic projects namely (PAL(all the web form interfaces are there) , BAL(refer business logic) and DAL ( refer data access -SQL server part). PAL is linked to BAL and BAL is LINKED to DAL. then i want to add a Ajax auto complete extender to a Textbox in a web form located at PAL .just say testwebform.aspx and i write a webService in a BAL namely webService1 and add a webmethod as follows..


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data;
using System.Data.Sql;
using AjaxControlToolkit;
using DAL;

namespace BAL
{
    /// <summary>
    /// Summary description for WebService1
    /// </summary>
    [WebService(Namespace = "http://testserver/webservices")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
     [System.Web.Script.Services.ScriptService]
     //[System.Web.Services.WebMethod]
     //[System.Web.Script.Services.ScriptMethod]

    public class WebService1 : System.Web.Services.WebService
    {

        [WebMethod]
        public String[] GetCompanyList(String prefixText, Int32 count)
        {
            String[] strList = null;
            List<string> strCompanyList = new List<string>();

            String Consigneeprefix = prefixText + "%";
            String Sql = "SELECT TOP''"+count+"''[conCode],[conName] FROM [tblConsignee] WHERE [cusCode] =''"+webSupport.ShipperCode().Trim() +"'' AND  [conName] LIKE''" + Consigneeprefix +"''";

// webSupport.ShipperCode refer to get the ShipperCode for Sql Query String via.

            DataTable dt = new DataTable();
            dt = SQLTrans.executeQuery(Sql, "tbl");

            if (dt.Rows.Count> 0)
 
            {
                for ( int i = 0 ; i< dt.Rows.Count;i++)
                {
                  // Here is the Douted area in web method.

                  strCompanyList.Add(AjaxControlToolkit.AutoCompleteExtender.
                  CreateAutoCompleteItem(dt.Rows[i][0].ToString(), Convert.ToString(dt.Rows[i][1].ToString())));


                }

                strList = new String[10];
                strList = strCompanyList.ToArray();


            }
            else
            {
                //No records found

            }
            
            return strList;
        }
    }
}





然后我通过使用以下AJAX自动完成扩展程序从PAL的特定Web表单调用Web服务方法.并显示服务器标签格式不正确".我引用将AJAX AutoCompleteExtender用于自动建议 [





then i called the web service method from PAL''s particular webform by using following AJAX auto completeextender as follows. and it says "Server tag is Not well formed". i refer Using AJAX AutoCompleteExtender for autosuggest[^] to get the idea of webServices and AJAX auto Complete extender.But i also dnt know how to Link return SQL query''s return two Fields([conCode],[conName]) values. it is conCode to a value flied of the Extender and conNameto Text feild in the Ajax extender.


<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

<asp:TextBox ID="TextBox1" runat="server" Height="19px" Width="256px"></asp:TextBox>
    
            <asp:AutoCompleteExtender ID="txtAutoCompleteforCompany_AutoCompleteExtender"
	            MinimumPrefixLength="1" TargetControlID="TextBox1" 
	            CompletionSetCount="10"CompletionInterval="100" 
	            ServiceMethod="GetCompanyList" 
	            ServicePath="../BAL/WebService1.asmx"
	            runat="server" OnClientItemSelected="setCompanyMasterID" 
	            CompletionListElementID="listPlacement">
            </asp:AutoCompleteExtender>




</asp:Content>





如果有人可以在这个问题上为我提供帮助,那么对我来说可能是一个很大的帮助.
在此先感谢!!!





If Someone Could help me on this matter it could be a great help for me.
Thanks in Advance!!!

推荐答案

完整的参考请点击这里


http://csharpdotnetfreak.blogspot.com/2009/01/ajax-autocomplete-textbox- gridview.html [ ^ ]
for complete refrence click here


http://csharpdotnetfreak.blogspot.com/2009/01/ajax-autocomplete-textbox-gridview.html[^]


找到了!您在这两个属性之间没有空格:

Found it! you haven''t got a space between these two attributes:

CompletionSetCount="10"CompletionInterval="100"



将以上内容更改为:



Change the above to:

CompletionSetCount="10" CompletionInterval="100"



看看是否可行.



See if this works.


这篇关于Asp.net WebForm中用于文本框的AJAX自动完成扩展器.(如何将.Net-WebService链接到AJAX自动完成扩展器!)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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