为什么repeater显示不了数据,,急,谢谢

来源:百度知道 编辑:UC知道 时间:2024/05/30 23:51:00
asp.net repeater老是无法显示数据, 怪!
cs/
<script runat="server">
private void Page_Load(object sender,System.EventArgs e)
{
querystr=Request.QueryString["searchn"].ToString();
proinfo_repter_bind();
}

void proinfo_repter_bind()
{
datacon();//链接数据库
string thestr="Select name from productiontb where name like'%"+querystr+"%'";
OleDbCommand theCOMD=accon.CreateCommand();
theCOMD.CommandText=thestr;
OleDbDataReader ckreader=theCOMD.ExecuteReader();
if(ckreader.Read())
{
thestr="Select name,imgurl,place,producetime,kucun,price,state from productiontb where name like'%"+querystr+"%'";
OleDbDataAdapter theADPT=new OleDbDataAdapter(thestr,accon);
DataSet thisDS=new DataSet();
theADPT.Fill(thisDS,"productiontb");
proinfo_repter.DataSource=thisDS.Tables["productiontb"].DefaultView;
proinfo

其实这种问题还是自己解决比较有成就感

在if(ckreader.Read())之前加入断点
然后看看后面的东西有没有执行以确定是不是从数据库中读出了东西
如果读出来就检查下面的代码
读不出来就是SQL语句错了 或者数据有问题

把问题细化

有要确定有没有数据,也就是你的DataSet集合中的表集合中是否没有数据。

另外,Repeater控件的数据时要绑定到ItemTemplate中的,这里我没有看到你的ItemTemplate哦。

proinfo_repter是不是在绑定数据后还要加一个flush的方法?

proinfo_repter.DataSource=thisDS.Tables
改为
proinfo_repter.DataSource=thisDS.Tables(0)试试