I am digesting a web serivce from Amazon.Com. I have the following
class which was autogenerated by VS.NET when I created a Web Reference
to http://webservices.amazon.com/AWSECo...ceService.wsdl
AmazonWebService.com.amazon.webservices.Item
As you can see from the code snippets below it has public member
variables rather than public Properties. When I use <%#
DataBinder.Eval(Container.DataItem, "ASIN") %> syntax in Repeater1 in
my aspx page I get the following error.
[HttpException (0x80004005): DataBinder.Eval:
'AmazonWebService.com.amazon.webservices.Item' does not contain a
property with the name ASIN.]
System.Web.UI.DataBinder.GetPropertyValue(Object container, String
propName)
System.Web.UI.DataBinder.Eval(Object container, String[]
expressionParts)
System.Web.UI.DataBinder.Eval(Object container, String expression)
ASP.SearchForm_aspx.__DataBind__control8(Object sender, EventArgs e)
in c:\inetpub\wwwroot\AmazonWebService\SearchForm.asp x:33
System.Web.UI.Control.OnDataBinding(EventArgs e)
System.Web.UI.Control.DataBind()
System.Web.UI.Control.DataBind()
System.Web.UI.WebControls.Repeater.CreateItem(Int3 2 itemIndex,
ListItemType itemType, Boolean dataBind, Object dataItem)
System.Web.UI.WebControls.Repeater.CreateControlHi erarchy(Boolean
useDataSource)
System.Web.UI.WebControls.Repeater.OnDataBinding(E ventArgs e)
System.Web.UI.WebControls.Repeater.DataBind()
AmazonWebService.Web.SearchForm.Button1_Click(Obje ct sender, EventArgs
e) in c:\inetpub\wwwroot\amazonwebservice\searchform.asp x.cs:83
System.Web.UI.WebControls.Button.OnClick(EventArgs e)
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
System.Web.UI.Page.ProcessRequestMain()
If I add a property to the Item class called ASINP, which encapsulates
ASIN member variable, and I use <%#
DataBinder.Eval(Container.DataItem, "ASINP") %> syntax in Repeater1 on
my aspx then everything works fine. Since the Item class is
autogenerated I do not want to have to add Properties in every
autogenerated class because I have about 40 auto generated classes.
How can I reference the memeber variable ASIN in the aspx page, or any
other memeber variable in that class.
Please see the code snippets below if you have questions.
Thanks,
Chris Gastin
CODE SNIPPETS:
////////////////////////////////////////////////////////////////////////////////////////////////////
// asp:Repeater
///////////////////////////////////////////////////////////////////////////////////////////////////
<asp:Repeater id="Repeater1" runat="server">
<HeaderTemplate>
<table border=1>
<tr>
<td>Results:</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td bgcolor="LightGrey">
<%# DataBinder.Eval(Container.DataItem, "ASIN") %>
</td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr>
<td bgcolor="Yellow">
<%# DataBinder.Eval(Container.DataItem, "ASIN") %>
</td>
</tr>
</AlternatingItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
////////////////////////////////////////////////////////////////////////////////////////////////////
// Button Click Event
///////////////////////////////////////////////////////////////////////////////////////////////////
private void Button1_Click(object sender, System.EventArgs e)
{
AWSECommerceService svc = new AWSECommerceService();
ItemSearchRequest itemSearchRequest = new ItemSearchRequest();
itemSearchRequest.Keywords = TextBox1.Text;
itemSearchRequest.SearchIndex = DropDownList1.SelectedValue;
itemSearchRequest.MerchantId = "All";
itemSearchRequest.ResponseGroup = new string[]{"Large"};
ItemSearch search = new ItemSearch();
search.SubscriptionId =
ConfigurationSettings.AppSettings["SubscriptionId"];
search.Request = new ItemSearchRequest[]{itemSearchRequest};
IAsyncResult result = svc.BeginItemSearch(search,null,null);
ItemSearchResponse searchResponse = svc.EndItemSearch(result);
Repeater1.DataSource = searchResponse.Items[0].Item;
Repeater1.DataBind();
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// Item Class
///////////////////////////////////////////////////////////////////////////////////////////////////
/// <remarks/>
[System.Xml.Serialization.XmlTypeAttribute(Namespac e="http://webservices.amazon.com/AWSECommerceService/2004-10-19")]
public class Item {
/// <remarks/>
public string ASIN;
/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("Er ror",
IsNullable=false)]
public ErrorsError[] Errors;
/// <remarks/>
public string DetailPageURL;
/// <remarks/>
public string SalesRank;
/// <remarks/>
public Image SmallImage;
/// <remarks/>
public Image MediumImage;
/// <remarks/>
public Image LargeImage;
/// <remarks/>
public ItemAttributes ItemAttributes;
/// <remarks/>
public OfferSummary OfferSummary;
/// <remarks/>
public Offers Offers;
/// <remarks/>
public VariationSummary VariationSummary;
/// <remarks/>
public Variations Variations;
/// <remarks/>
public CustomerReviews CustomerReviews;
/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("Ed itorialReview",
IsNullable=false)]
public string[] EditorialReviews;
/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("Si milarProduct",
IsNullable=false)]
public SimilarProductsSimilarProduct[] SimilarProducts;
/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("Si milarBusiness",
IsNullable=false)]
public SimilarBusinessesSimilarBusiness[] SimilarBusinesses;
/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("Ac cessory",
IsNullable=false)]
public AccessoriesAccessory[] Accessories;
/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("Di sc",
IsNullable=false)]
public TracksDisc[] Tracks;
/// <remarks/>
public BrowseNodes BrowseNodes;
/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("Li stmaniaList",
IsNullable=false)]
public ListmaniaListsListmaniaList[] ListmaniaLists;
/// <remarks/>
public SearchInside SearchInside;
/// <remarks/>
public PromotionalTag PromotionalTag;
}