四创建一个web服务以便从数据库取得数据 现在我们已经配置完毕数据集接下来我们将编写一个web服务以便针对一个给定的CarId得到所有的汽车模型后面这个web服务将由我们的cascadingdropdown控件使用下一节中我们将讨论如何配置CascadingDropDown以便使用这个web服务 【第一步】右击工程并点击添加新项…在添加新项对话框中从已安装的模板列表中选择Web服务并且命名为CarsServiceasmx(如图所示) )thisstylewidth=;>图在工程中添加Web服务模板【第二步】通过第一步有两个文件将被创建到你的应用程序中一个是CarsServiceasmx位于你的应用程序根目录下另一个是CarsServicecs位于App_Code文件夹下相应于该web服务的CodeBehind文件 【第三步】打开上面的文件CarsServicecs我们要在这个文件中编写web方法来实现前面的目标 【第四步】在当前文件中添加下列必要的命名空间(加粗部分) borderColorDark=#ffffff cellPadding= width= align=center borderColorLight=black border=>ee> using System; using SystemWeb; using SystemCollections; using SystemWebServices; using SystemWebServicesProtocols; using SystemCollectionsGeneric;using AjaxControlToolkit; using SystemData; using SystemDataSqlClient;
【第五步】应该使用ScriptService属性来修饰你的web服务为此在类定义的上面添加下列一行(加粗部分) right>[http://developcsaicn/dotnet/htm>] [http://developcsaicn/dotnet/htm>] [http://developcsaicn/dotnet/htm>] [] [http://developcsaicn/dotnet/htm>] [http://developcsaicn/dotnet/htm>] |