我有一个名为“Entries”的表,并且正在使用LINQ to SQL进行数据访问。我创建了一个获取所有条目的存储过程。我已经将存储的proc映射到数据上下文中的方法,我已将返回类型设置为“Entry”。'object'在ascx文件中不包含使用repeater的定义错误
我在我的数据访问类中创建了一个方法,它将此方法调用的结果作为List返回。我的列表绑定到一个中继器在用户控制,并试图在我的ascx文件访问属性“ENTRYID”和我收到以下错误:
“对象”不包含“ENTRYID”
的定义我在我的数据访问类方法:
public static List<Entry> GetAllEntries()
{
using (DataClassesDataContext context = new DataClassesDataContext())
{
return context.fbGetAllEntries().ToList();
}
}
和用户控制Page_PreRender事件:
//my alias at the top of the file for clairification
using ASPWebControls = System.Web.UI.WebControls;
protected void Page_PreRender(System.Object sender, System.EventArgs e)
{
rptEntries = new ASPWebControls.Repeater();
rptEntries.DataSource = DataAccess.GetAllEntries();
rptEntries.DataBind();
}
而且在我的ascx文件:
<asp:Repeater ID = "rptEntries" runat = "server" >
<ItemTemplate>
<tr>
<td><input type="checkbox" runat="server" value="<%# Container.DataItem.EntryId %>" /></td>
</tr>
</ItemTemplate>
</asp:Repeater>
当我谷歌搜索这个错误,我发现它可以发生在使用匿名类型时,但这不是这里的情况。我确定我的转发器有一个绑定到它的强类型对象的列表。我试过explicitally铸造:
rptEntries.DataSource = (List<Entry>)DataAccess.GetAllEntries();
我敢肯定我的条目类型有ENTRYID我能做到这一点:
foreach (Entry en in (List<Entry>)rptEntries.DataSource)
{
//when I step through I can see these are the correct values
int i = en.EntryId;
}
我试着输入我的名字空间在我的ascx文件:
<%@ Import NameSpace="Namespace.in.my.DataClass.cs" %>
我不确定哪里的事情横向,有人可以提出我做错了什么?任何帮助将不胜感激,谢谢!
编辑:错过了一个代码块
这似乎这样做,谢谢! – TheMethod