2010-10-26 73 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