Problem Binding Propertyless Class to a Repeater

G

Gastin

I am consuming 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/AWSECommerceService/AWSECommerceService.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.aspx:33
System.Web.UI.Control.OnDataBinding(EventArgs e)
System.Web.UI.Control.DataBind()
System.Web.UI.Control.DataBind()
System.Web.UI.WebControls.Repeater.CreateItem(Int32 itemIndex,
ListItemType itemType, Boolean dataBind, Object dataItem)
System.Web.UI.WebControls.Repeater.CreateControlHierarchy(Boolean
useDataSource)
System.Web.UI.WebControls.Repeater.OnDataBinding(EventArgs e)
System.Web.UI.WebControls.Repeater.DataBind()
AmazonWebService.Web.SearchForm.Button1_Click(Object sender, EventArgs
e) in c:\inetpub\wwwroot\amazonwebservice\searchform.aspx.cs:83
System.Web.UI.WebControls.Button.OnClick(EventArgs e)
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection 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(Namespace="http://webservices.amazon.com/AWSECommerceService/2004-10-19")]
public class Item {

/// <remarks/>
public string ASIN;

/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("Error",
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("EditorialReview",
IsNullable=false)]
public string[] EditorialReviews;

/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("SimilarProduct",
IsNullable=false)]
public SimilarProductsSimilarProduct[] SimilarProducts;

/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("SimilarBusiness",
IsNullable=false)]
public SimilarBusinessesSimilarBusiness[] SimilarBusinesses;

/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("Accessory",
IsNullable=false)]
public AccessoriesAccessory[] Accessories;

/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("Disc",
IsNullable=false)]
public TracksDisc[] Tracks;

/// <remarks/>
public BrowseNodes BrowseNodes;

/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("ListmaniaList",
IsNullable=false)]
public ListmaniaListsListmaniaList[] ListmaniaLists;

/// <remarks/>
public SearchInside SearchInside;

/// <remarks/>
public PromotionalTag PromotionalTag;
}
 
S

Scott Allen

Hi Gastin:

You do not have to use DataBinder.Eval in data binding expressions,
you can call your own static method or even cast the DataContainer to
the correct type.

I have some examples here:

Digging into DataBinding Expressions
http://odetocode.com/Articles/278.aspx

HTH,

--
Scott
http://www.OdeToCode.com/blogs/scott/\

I am consuming 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/AWSECommerceService/AWSECommerceService.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.aspx:33
System.Web.UI.Control.OnDataBinding(EventArgs e)
System.Web.UI.Control.DataBind()
System.Web.UI.Control.DataBind()
System.Web.UI.WebControls.Repeater.CreateItem(Int32 itemIndex,
ListItemType itemType, Boolean dataBind, Object dataItem)
System.Web.UI.WebControls.Repeater.CreateControlHierarchy(Boolean
useDataSource)
System.Web.UI.WebControls.Repeater.OnDataBinding(EventArgs e)
System.Web.UI.WebControls.Repeater.DataBind()
AmazonWebService.Web.SearchForm.Button1_Click(Object sender, EventArgs
e) in c:\inetpub\wwwroot\amazonwebservice\searchform.aspx.cs:83
System.Web.UI.WebControls.Button.OnClick(EventArgs e)
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection 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(Namespace="http://webservices.amazon.com/AWSECommerceService/2004-10-19")]
public class Item {

/// <remarks/>
public string ASIN;

/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("Error",
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("EditorialReview",
IsNullable=false)]
public string[] EditorialReviews;

/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("SimilarProduct",
IsNullable=false)]
public SimilarProductsSimilarProduct[] SimilarProducts;

/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("SimilarBusiness",
IsNullable=false)]
public SimilarBusinessesSimilarBusiness[] SimilarBusinesses;

/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("Accessory",
IsNullable=false)]
public AccessoriesAccessory[] Accessories;

/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("Disc",
IsNullable=false)]
public TracksDisc[] Tracks;

/// <remarks/>
public BrowseNodes BrowseNodes;

/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("ListmaniaList",
IsNullable=false)]
public ListmaniaListsListmaniaList[] ListmaniaLists;

/// <remarks/>
public SearchInside SearchInside;

/// <remarks/>
public PromotionalTag PromotionalTag;
}
 
G

Gastin

Scott:

Thanks for the response. Acutally after a little digging an
experimenting I realized I did not have to use the DataBinder.Eval in
my data binding expression.

I used casted Container.DataItem to the instatitated object Item like
this.

<%#((Item)Container.DataItem).ASIN%>

Again than for the links. This is giving me insight into how data bind
works. I really appreciate you assitance.

Thanks
Chris Gastin
"Java Developer trying to learn .NET"

Scott Allen said:
Hi Gastin:

You do not have to use DataBinder.Eval in data binding expressions,
you can call your own static method or even cast the DataContainer to
the correct type.

I have some examples here:

Digging into DataBinding Expressions
http://odetocode.com/Articles/278.aspx

HTH,

--
Scott
http://www.OdeToCode.com/blogs/scott/\

I am consuming 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/AWSECommerceService/AWSECommerceService.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.aspx:33
System.Web.UI.Control.OnDataBinding(EventArgs e)
System.Web.UI.Control.DataBind()
System.Web.UI.Control.DataBind()
System.Web.UI.WebControls.Repeater.CreateItem(Int32 itemIndex,
ListItemType itemType, Boolean dataBind, Object dataItem)
System.Web.UI.WebControls.Repeater.CreateControlHierarchy(Boolean
useDataSource)
System.Web.UI.WebControls.Repeater.OnDataBinding(EventArgs e)
System.Web.UI.WebControls.Repeater.DataBind()
AmazonWebService.Web.SearchForm.Button1_Click(Object sender, EventArgs
e) in c:\inetpub\wwwroot\amazonwebservice\searchform.aspx.cs:83
System.Web.UI.WebControls.Button.OnClick(EventArgs e)
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection 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(Namespace="http://webservices.amazon.com/AWSECommerceService/2004-10-19")]
public class Item {

/// <remarks/>
public string ASIN;

/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("Error",
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("EditorialReview",
IsNullable=false)]
public string[] EditorialReviews;

/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("SimilarProduct",
IsNullable=false)]
public SimilarProductsSimilarProduct[] SimilarProducts;

/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("SimilarBusiness",
IsNullable=false)]
public SimilarBusinessesSimilarBusiness[] SimilarBusinesses;

/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("Accessory",
IsNullable=false)]
public AccessoriesAccessory[] Accessories;

/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("Disc",
IsNullable=false)]
public TracksDisc[] Tracks;

/// <remarks/>
public BrowseNodes BrowseNodes;

/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("ListmaniaList",
IsNullable=false)]
public ListmaniaListsListmaniaList[] ListmaniaLists;

/// <remarks/>
public SearchInside SearchInside;

/// <remarks/>
public PromotionalTag PromotionalTag;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top