我对使用Linq-to-SQL非常陌生,这就是为什么我要问这个问题。我搜索了该网站,但似乎无法弄清楚如何做到这一点。将两个sql表数据绑定到一个中继器
我的问题是:
我有一个数据库映射与LINQ到SQL:
表1:PersonalTasks
TaskId
Header
[Content]
IsDone
CreatedDate
表2:评论
CommentId
TaskId
UserId
Comment
CreatedDate
我有一个中继器:
<asp:Repeater ID="PersonalTaskRepeater" runat="server">
<ItemTemplate>
<%#Eval("Header") %>
<%# Eval("Content") %>
Task done: <asp:CheckBox ID="IsDoneCheckBox" runat="server" Checked='<%#Eval("IsDone") %>' /><img src="Images/tick-circle.png" />
Here i want to access the comment table, with the comments related to the taskID
</ItemTemplate>
</asp:Repeater>
我已经尝试使用:<%#Eval("Comment.Comment1")%>
但引发此错误:
DataBinding: 'System.Data.Linq.EntitySet`1[[Assistr.Models.Comment, Assistr, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' does not contain a property with the name 'Comment'.
我的后台代码:
var tasks = db.PersonalTasks.OrderBy(x => x.IsDone).ToList();
PersonalTaskRepeater.DataSource = tasks;
PersonalTaskRepeater.DataBind();
我是否需要使用2个中继器做我想做的事情还是? :)
感谢提前:)
//的Mads
如果您发布的是代码或XML,请**在文本编辑器中突出显示这些行,然后单击编辑器工具栏上的“代码”按钮(101 010),以良好地格式化和语法突出显示它! – 2010-10-26 16:57:38