469,889 Members | 1,257 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,889 developers. It's quick & easy.

Problem Binding Propertyless Class to a Repeater

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/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;
}
Nov 18 '05 #1
2 2150
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/\

On 30 Oct 2004 19:34:45 -0700, ch***@gastin.com (Gastin) wrote:
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/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(Objec t 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(Int 32 itemIndex,
ListItemType itemType, Boolean dataBind, Object dataItem)
System.Web.UI.WebControls.Repeater.CreateControlH ierarchy(Boolean
useDataSource)
System.Web.UI.WebControls.Repeater.OnDataBinding( EventArgs e)
System.Web.UI.WebControls.Repeater.DataBind()
AmazonWebService.Web.SearchForm.Button1_Click(Obj ect sender, EventArgs
e) in c:\inetpub\wwwroot\amazonwebservice\searchform.asp x.cs:83
System.Web.UI.WebControls.Button.OnClick(EventArg s e)
System.Web.UI.WebControls.Button.System.Web.UI.IP ostBackEventHandler.RaisePostBackEvent(String
eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEv entHandler
sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCo llection 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;
}


Nov 18 '05 #2
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 <bitmask@[nospam].fred.net> wrote in message news:<t2********************************@4ax.com>. ..
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/\

On 30 Oct 2004 19:34:45 -0700, ch***@gastin.com (Gastin) wrote:
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/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(Objec t 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(Int 32 itemIndex,
ListItemType itemType, Boolean dataBind, Object dataItem)
System.Web.UI.WebControls.Repeater.CreateControlH ierarchy(Boolean
useDataSource)
System.Web.UI.WebControls.Repeater.OnDataBinding( EventArgs e)
System.Web.UI.WebControls.Repeater.DataBind()
AmazonWebService.Web.SearchForm.Button1_Click(Obj ect sender, EventArgs
e) in c:\inetpub\wwwroot\amazonwebservice\searchform.asp x.cs:83
System.Web.UI.WebControls.Button.OnClick(EventArg s e)
System.Web.UI.WebControls.Button.System.Web.UI.IP ostBackEventHandler.RaisePostBackEvent(String
eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEv entHandler
sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCo llection 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;
}

Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Stephen Miller | last post: by
2 posts views Thread by Donald Williamson | last post: by
2 posts views Thread by Colin Nicholls | last post: by
4 posts views Thread by Brad Baker | last post: by
12 posts views Thread by =?Utf-8?B?Qi4gQ2hlcm5pY2s=?= | last post: by
2 posts views Thread by Hong | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.