Click here to Skip to main content
15,891,713 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm beginner in Asp.Net and I'm trying to display "gc" on repeat control.

Here's the code-behind:
C#
public partial class _Default : System.Web.UI.Page
                {       
       List<GlassesCollection> gc= BL.Example.GetCategory() ;     
       protected void Page_Load(object sender, EventArgs e)  
               {        
                 rpt1.DataSource = gc;        
                 rpt1.DataBind();     
               }    
  protected void rpt1_ItemDataBound(object sender, RepeaterItemEventArgs e) 
        {
        }

Im using the following ASP code:
ASP.NET
<asp:Repeater ID="rpt1" runat="server" onitemdatabound="rpt1_ItemDataBound">

 <ItemTemplate>  
       <%# Eval("gc") %>   
  </ItemTemplate>
</asp:Repeater>

But in run time i get this Exception:
Exception Details: System.Web.HttpException: DataBinding: 'ISeeOptic.DataType.GlassesCollection' does not contain a property with the name 'gc'.
Why i get this Exception and idea how to solve this?

Thank you in advance!
Posted
Updated 6-Jan-12 6:43am
v2

1 solution

Your item ItemTemplate needs to define how each record will be displayed.
When you set your datasource to "gc" and databind it, the Eval in your ItemTemplate is going to check the gc object for a property named "gc" which of course it does not and that is why you get the error.
Say, for example, that your GlassesCollection contains objects of type Glass and that the Glass class contains two properties Id and Description. Then, if you want to use the repeater control, you would have an itemtemplate something like this
XML
<itemtemplate>
   Id = <%# Eval("Id") %>
   Description = <%# Eval("Description") %>
</itemtemplate>


If you actually want your data in a grid type display, I would suggest that you use the DataGridView control instead.
XML
<asp:datagridview id="dgData" runat="server" xmlns:asp="#unknown"></asp:datagridview>

C#
dgData.Datasource = gc;
dgData.ResetBindings();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900