获取转发器控制异常 [英] getting repeater control exception

查看:96
本文介绍了获取转发器控制异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Asp.Net的初学者,我正在尝试在重复控件上显示"gc".

这是隐藏的代码:

I''m beginner in Asp.Net and I''m trying to display "gc" on repeat control.

Here''s the code-behind:

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) 
        {
        }


我正在使用以下ASP代码:


Im using the following ASP code:

<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!

推荐答案

您的项目ItemTemplate需要定义每条记录的显示方式.
当您将数据源设置为"gc"并进行数据绑定时,ItemTemplate中的Eval将检查gc对象中是否有名为"gc"的属性,这当然不是,这就是为什么会出现错误.
例如,假设您的GlassesCollection包含类型为Glass的对象,并且Glass类包含两个属性Id和Description.然后,如果要使用转发器控件,将有一个像这样的itemtemplate
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
<itemtemplate>
   Id = <%# Eval("Id") %>
   Description = <%# Eval("Description") %>
</itemtemplate>



如果您实际上希望数据以网格类型显示,则建议您改用DataGridView控件.



If you actually want your data in a grid type display, I would suggest that you use the DataGridView control instead.

<asp:datagridview id="dgData" runat="server" xmlns:asp="#unknown"></asp:datagridview>


dgData.Datasource = gc;
dgData.ResetBindings();


这篇关于获取转发器控制异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆