问题描述
ASPX代码:<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="repeater.aspx.cs"Inherits="repeater"%><%@ImportNamespace="System.Data"%><!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><headrunat="server"><title>无标题页</title></head><body><formid="form1"runat="server"><div><asp:RepeaterID="Repeater1"runat="server"><ItemTemplate><table><tr><td>分类名</td></tr><tr><td><%#Eval("BoardID")%></td></tr></table</ItemTemplate></asp:Repeater></div></form></body></html>CS代码:usingSystem;usingSystem.Data;usingSystem.Data.SqlClient;usingSystem.Configuration;usingSystem.Collections;usingSystem.Web;usingSystem.Web.Security;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Web.UI.WebControls.WebParts;usingSystem.Web.UI.HtmlControls;publicpartialclassrepeater:System.Web.UI.Page{privatestringSconnection=@"server=.;database=bbs;uid=sa;pwd=wwwtqbbacom";protectedvoidPage_Load(objectsender,EventArgse){if(!IsPostBack){setbind();}}protectedvoidsetbind(){DataSetds=newDataSet();using(SqlConnectionconn=newSqlConnection(Sconnection)){SqlDataAdaptersd=newSqlDataAdapter("Select*fromtbClass;Select*fromtbBoard",conn);sd.Fill(ds);}Repeater1.DataSource=ds;Repeater1.DataBind();}}出现DataBinding:“System.Data.DataRowView”不包含名为“BoardID”的属性。是为什么???
解决方案
解决方案二:
SqlDataAdaptersd=newSqlDataAdapter("Select*fromtbClass;Select*fromtbBoard",conn);为什么要写2个查询?这样DataSet有2个DataTableRepeater1.DataSource=ds;//这里不要写DataSet,换成DataTableRepeater1.DataBind();
解决方案三:
恩.本来DS有个relation.所以查了两个表.我发上来的时候没去掉.Repeater1.DataSource=ds;//这里不要写DataSet,换成DataTable这里换成DataTable就OK了吗?我试一下..
解决方案四:
可以了.一个Repeater只能绑一个数据表吗?
解决方案五:
可能吧,基础的东西,咋也没了解太深,太细