Atlas 学习笔记: ajax 改进 by Atlas

废话不多说,今天试试atlas

1.       加入atlas 的 scriptManager   因为是后台直接调webservice  所以加上webservice的地址

         < atlas:ScriptManager  ID ="scriptManager"  runat ="server" >
        
< Services >
            
< atlas:ServiceReference  Path ="WebService.asmx"   />
        
</ Services >
    
</ atlas:ScriptManager >


2.         OK 在来一个text    注意在后面 spanid 要加一个名字 这个名字要和下面对应起来
     < input  id ="Text1"  type ="text"   />< span  id ="Text1__autocomplete" ></ span >


3.        这段代码大家看看  指定  text1 要完成的行为   behaviors 里面指定了autoComplete 指定了方法serviceMethod="GetCompletionList"      minimumPrefixLength ="1" 指定你输入多少个字符就开始触发这个auto事件最后  completionList ="Text1__autocomplete" 这个名字和第二步的名字 要统一
   < script  type ="text/xml-script" >
  
<page xmlns:script="http://schemas.microsoft.com/xml-script/2005">
    
<components>
    
      
<label id="Text1" targetElement="Text1">
        
<behaviors>
          
<autoComplete serviceURL="WebService.asmx" serviceMethod="GetCompletionList" minimumPrefixLength="1" completionList="Text1__autocomplete" />
        
</behaviors>
      
</label>
      
    
</components>
    
<references>
    
</references>
  
</page>
</ script >


4   下面来写webservice时候实现 的代码  基本上就是一个查询 注意返回值的类型
    [WebMethod]
    
public   string [] GetCompletionList( string  prefixText)
    
{
        
string temp = "";
        List
<string> suggestions = new List<string>();
        
if (prefixText != "")
        
{
            
string mySelectQuery = "SELECT ContactName FROM Customers where ContactName like '" + prefixText + "%'";
            SqlConnection myConnection 
= new SqlConnection(@"server=ZTE-WUANCHENG/wuancheng_zte;database=Northwind;User ID=sa;password=;Persist Security Info=true;");
            SqlCommand myCommand 
= new SqlCommand(mySelectQuery, myConnection);
            myConnection.Open();
            SqlDataReader myReader 
= myCommand.ExecuteReader();
            
            
try
            
{               
                
while (myReader.Read())
                
{
                    suggestions.Add(myReader.GetString(
0));
                    temp 
= temp + myReader.GetString(0+ "";
                }

                
            }

            
finally
            
{
                
// always call Close when done reading.
                myReader.Close();
                
// always call Close when done reading.
                myConnection.Close();
            }

        }



        
return suggestions.ToArray();
    }



5 . ok  看看效果


 

http://www.cnblogs.com/arthur_wuancheng/archive/2006/03/16/351319.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值