datalist 多表查询绑定出错!
提示错误:DataBinder.Eval:“System.Data.DataRowView”不包含名称为 SubjectID 的属性。
前台:
<TABLE class="Broad" id="Table6" height="100%" cellSpacing="0" cellPadding="0" width="100%" border="0">
<TR>
<TD width="100%"><asp:datalist id="SubjectDataList" runat="server" Width="100%" DataKeyField="SubjectID" Height="100%">
<ItemTemplate>
<table cellSpacing="0" cellPadding="0" width="100%" border="0">
<TR>
<TD class="BroadHeader"><%# DataBinder.Eval(Container.DataItem,"Title") %></TD>
</TR>
<tr>
<td class="BroadHeader"><%# DataBinder.Eval(Container.DataItem,"SubjectName") %>(<%# DataBinder.Eval(Container.DataItem,"SelectMode").ToString().Trim()=="single"?"单选":"多选" %>)</td>
</tr>
<tr>
<td width="100%">
<asp:PlaceHolder id="pollholder" runat="server"> </asp:PlaceHolder> </td>
</tr>
</table> </ItemTemplate> </asp:datalist></TD>
</TR>
<TR>
<TD align="middle" width="100%"><asp:button id="BtnRefer" runat="server" Width="60px" Text="提交" CssClass="Button"></asp:button></TD>
</TR>
</TABLE>
后台
string ConnStr = System.Configuration.ConfigurationSettings.AppSettings["DSN"];
SqlConnection myConnection = new SqlConnection(ConnStr);
myConnection.Open();
string sqlStr3 = "SELECT top 1 PollTitle.Title,PollSubject.SubjectID,PollSubject.SubjectName,PollSubject.SelectMode FROM PollTitle,PollSubject,PollOptions WHERE PollSubject.SubjectID=PollOptions.SubjectID AND PollTitle.TitleID=PollSubject.TitleID ORDER BY PollOptions.dateandtime DESC ";
SqlCommand myCommand3 = new SqlCommand( sqlStr3 ,myConnection);
SqlDataAdapter dr3 = new SqlDataAdapter(myCommand3);
// 生成DataSet对象并填充数据
DataSet ds3 = new DataSet();
dr.Fill(ds3,"Subjecttable");
this.SubjectDataList.DataSource=ds3.Tables["Subjecttable"].DefaultView;
this.SubjectDataList.DataBind();
dr3.Dispose();
myConnection.Close();