储搜索结果及潜在的错误消息结果。
3.为了注册将触发部分更新的控件,把下列代码片断放到UpdatePanel控件的<Triggers>和</Triggers>元素之间:
<atlas:ControlEventTrigger ControlID="submitSearch" EventName="Click" />
<atlas:ControlEventTrigger ControlID="listBoxCity" EventName="SelectedIndexChanged" />
<atlas:ControlEventTrigger ControlID="listBoxCuisine" EventName="SelectedIndexChanged" />
(六) 在客户端应用程序添加代码
切换到设计视图,双击生成的Web表单以显示页面相应的代码部分(Default.aspx.cs)。选择Ctrl+A来选择所有的自动生成的代码,并按Delete键清除文档。然后,添加下列代码以消费Amazon ECS服务并且显示搜索结果:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected AWSECommerceService AmazonECS = new AWSECommerceService();
protected ItemSearch Search = new ItemSearch();
protected ItemSearchRequest SearchRequest = new ItemSearchRequest();
protected ItemSearchResponse SearchResponse;
protected void submitSearch_Click(object sender, EventArgs e)
{
Search.AWSAccessKeyId = TxtBAccessKey.Text.ToString();
SearchRequest.SearchIndex = "Restaurants";
SearchRequest.Cuisine = ListBoxCuisine.SelectedValue;
SearchRequest.City = listBoxCity.SelectedValue;
SearchRequest.Neighborhood = TextBox3.Text.ToString();
SearchRequest.ResponseGroup = new String[] { "ItemAttributes" };
Search.Request = new ItemSearchRequest[1] { SearchRequest };
try
{
SearchResponse = AmazonECS.ItemSearch(Search);
if (SearchResponse.Items == null)
{ labelError.Text = "A Server error has occured."; }
else
{
Items responseItems = SearchResponse.Items[0];
Item[] response = responseItems.Item;
if (response != null)
{
foreach (Item I in response)
{
NoResults.Text = "";
Label Results = new Label();
Label Sep = new Label();
Results.Text = "<strong>" + I.ItemAttributes.Title.ToUpper() + "</strong>" + "<br/>"
+ I.ItemAttributes.Address.Address1.ToString() + "<br/>"
+ I.ItemAttributes.Neighborhood + "<br/>"
+ "Tel:" + " " + I.ItemAttributes.PhoneNumber + "<br/>"
+ "Price Rating:" + " " + priceRating(I.ItemAttributes.PriceRating)+"<br/>"+"<br/>";
Sep.Text = "<br/>";
RP1.Controls.Add(Results);
RP1.Controls.Add(Sep); }
PriceRange.Text ="Price per person (based on entree, appetizer or salad, one non-alcoholic drink plus tax and tip)";
}
else
{
NoRes
|