Atlas 学习笔记: ajax 改进 by Atlas
2006-03-16 13:26
323 查看
废话不多说,今天试试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>
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 看看效果
还可以把 参考了altas 的例子
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>
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 看看效果
还可以把 参考了altas 的例子
相关文章推荐
- Atlas 学习笔记: ajax 改进 by Atlas
- AJAX学习笔记(五)——JSON格式
- ASP.NET AJAX (Atlas)学习
- jQuery学习笔记:Ajax(一)
- ajaxPro /prototype.js 学习笔记
- Ajax基础教程整理,学习笔记
- PHP学习笔记(六):通过ajax实时匹配后台的数据
- [学习笔记]ajax 动态加载的FAQ (frequently asked question)
- Angularjs学习笔记——Ajax服务(跨域)&&ng路由
- 以XML格式传输数据 (2)--Ajax学习笔记
- Ajax 框架学习笔记
- Ajax基础学习笔记一
- 学习笔记之MVC级联及Ajax操作
- AjaxToolKit学习笔记 之 ModalPopupExtender
- ASP.NET 3.5核心编程学习笔记(52):Microsoft AJAX JavaScript类库
- ASP.NET 3.5核心编程学习笔记(56):AJAX Web Service的调用
- 黑马程序员之ASP.NET学习笔记:AJAX解决什么问题?如何使用AJAX?
- jQuery学习笔记10:Ajax技术
- Ajax 学习笔记(1)
- ajax,json学习笔记(四)跨域