Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Amazon Wev services (ECS 4.0) Questions

Status
Not open for further replies.

stfarm

Programmer
May 31, 2001
179
0
0
CA
Hi Guys,

is anybody experienced with the Amazon web services?
I downloaded the ASP.NET sample in VB.NET form the Amazon site, and I would like to add some images to the display, but when I add item.MediumImages, I get nothing. I am sure I am just overlooking something.

Thank you for the help.
Steve

Like to code on Amazon:



Imports System
Imports System.Data
Imports System.Drawing
Imports System.Web
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls

Namespace amazon

Public Class AmazonItemSearchControl
Inherits System.Web.UI.UserControl

'web controls
Protected searchTermLabel As System.Web.UI.WebControls.Label
Protected errorMessageLabel As System.Web.UI.WebControls.Label
Protected searchTermTextBox As System.Web.UI.WebControls.TextBox
Protected WithEvents resultSetDataGrid As System.Web.UI.WebControls.DataGrid
' Protected searchButton As System.Web.UI.WebControls.Button
Protected WithEvents searchButton As System.Web.UI.WebControls.Button
Protected totalResultsLabel As System.Web.UI.WebControls.Label
Protected totalResultsLabelText As System.Web.UI.WebControls.Label
'Amazon Service classes
Private amazonService As AWSECommerceService = New AWSECommerceService
Private itemSearch As ItemSearch = New ItemSearch
Private itemSearchRequest As ItemSearchRequest = New ItemSearchRequest
Private itemSearchResponse As ItemSearchResponse
'data binding classes
Private dataTable As DataTable = New DataTable
'public properties for subscriptionID and associateTag
Private _SubscriptionID As String = "XXX"
Private _AssociateTag As String = "XXX"
Public Property SubscriptionID() As String
Get
Return _SubscriptionID
End Get
Set(ByVal Value As String)
_SubscriptionID = Value
End Set
End Property

Public Property AssociateTag() As String
Get
Return _AssociateTag
End Get
Set(ByVal Value As String)
_AssociateTag = Value
End Set
End Property

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'create columns for data table
dataTable.Columns.Add(New DataColumn("Title", GetType(System.String)))
dataTable.Columns.Add(New DataColumn("Author", GetType(System.String)))
dataTable.Columns.Add(New DataColumn("ProductGroup", GetType(System.String)))
dataTable.Columns.Add(New DataColumn("AmazonURL", GetType(System.String)))
dataTable.Columns.Add(New DataColumn("MediumImg", GetType(System.String)))
End Sub

Private Sub searchButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles searchButton.Click
'reset the current page index
resultSetDataGrid.CurrentPageIndex = 0
SendQueryToAmazon("1")
End Sub

Private Sub resultSetDataGridPageIndexChanged(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles resultSetDataGrid.PageIndexChanged
'set the new current page index from the event
resultSetDataGrid.CurrentPageIndex = e.NewPageIndex
'page index is zero-based so we need to add one
SendQueryToAmazon((e.NewPageIndex + 1).ToString)
End Sub

Private Sub SendQueryToAmazon(ByVal pageNumber As String)
'clear datatable
dataTable.Rows.Clear()
'clear error label
errorMessageLabel.Text = ""
'build request to Amazon
itemSearch.SubscriptionId = Me.SubscriptionID
itemSearch.AssociateTag = Me.AssociateTag
itemSearchRequest.Keywords = searchTermTextBox.Text
itemSearchRequest.SearchIndex = "Blended"
itemSearchRequest.ResponseGroup = New String() {"Small"}
itemSearchRequest.ItemPage = pageNumber
itemSearch.Request = New ItemSearchRequest() {itemSearchRequest}
'send the query
Try
itemSearchResponse = amazonService.ItemSearch(itemSearch)
Catch e As Exception
errorMessageLabel.Text = e.Message
Return
End Try
Dim itemsResponse() As Items = itemSearchResponse.Items
' Check for errors in the reponse
If (itemsResponse Is Nothing) Then
errorMessageLabel.Text = "Server Error"
Return
End If
If (Not (itemsResponse(0).Request.Errors) Is Nothing) Then
errorMessageLabel.Text = itemsResponse(0).Request.Errors(0).Message
Return
End If
If (Not (itemsResponse) Is Nothing) Then
'note that we only sent one request
'so we only have one response, which is the first
Dim items As Items = itemsResponse(0)
If (Not (items) Is Nothing) Then
'display total results
totalResultsLabelText.Visible = True
totalResultsLabel.Text = items.TotalResults
'need to set the total result for paging purposes
resultSetDataGrid.VirtualItemCount = [Convert].ToInt32(items.TotalResults)
Dim results() As Item = items.Item
If (Not (results) Is Nothing) Then
Dim enumerator As System.Collections.IEnumerator = CType(results, System.Collections.IEnumerable).GetEnumerator
Do While enumerator.MoveNext
Dim item As Item = CType(enumerator.Current, Item)
If (Not (item) Is Nothing) Then
'create a datarow, populate it and add it to the table
Dim dataRow As DataRow = dataTable.NewRow
If (Not (item.ItemAttributes.Title) Is Nothing) Then
dataRow("Title") = item.ItemAttributes.Title
End If
If (Not (item.ItemAttributes.Author) Is Nothing) Then
dataRow("Author") = item.ItemAttributes.Author(0)
End If
If (Not (item.ItemAttributes.ProductGroup) Is Nothing) Then
dataRow("ProductGroup") = item.ItemAttributes.ProductGroup
End If
If (Not (item.DetailPageURL) Is Nothing) Then
dataRow("AmazonURL") = item.DetailPageURL
End If
If (Not (item.MediumImage) Is Nothing) Then
dataRow("MediumImg") = item.MediumImage
End If
dataTable.Rows.Add(dataRow)
End If
Dim dv As DataView = New DataView(dataTable)
'databinding the dataview to the datagrid
resultSetDataGrid.DataSource = dv
resultSetDataGrid.DataBind()

Loop
End If
End If
End If
Return
End Sub
Protected Overrides Sub OnInit(ByVal e As EventArgs)
InitializeComponent()
MyBase.OnInit(e)
End Sub

Private Sub InitializeComponent()

End Sub
End Class
End Namespace



Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top