2010-10-26 36 views
0

我对使用Linq-to-SQL非常陌生,这就是为什么我要问这个问题。我搜索了该网站,但似乎无法弄清楚如何做到这一点。将两个sql表数据绑定到一个中继器

我的问题是:

我有一个数据库映射与LINQ到SQL:

表1:PersonalTask​​s

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

+0

如果您发布的是代码或XML,请**在文本编辑器中突出显示这些行,然后单击编辑器工具栏上的“代码”按钮(101 010),以良好地格式化和语法突出显示它! – 2010-10-26 16:57:38

回答

0

我相信,如果你在同一个中继想的东西,你就必须来准备数据源,使数据得到有效联合在一起,并同使用的字段名称。 如果两组数据不同,那么为什么他们在同一个中继器?你想做什么。

+0

我不知道我是这样做的权利,这就是为什么我问这里:) – 2010-10-26 16:58:59

+0

我有这种关系:PersonalTask​​.TaskId - >评论。任务标记 – 2010-10-26 16:59:48

+0

嘿队友没有流行! – brumScouse 2010-10-26 17:18:37

相关问题