注册 登录
编程论坛 ASP.NET技术论坛

asp.net repeater老是无法显示数据, 怪!

guming 发布于 2009-11-25 16:11, 883 次点击
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();

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");
proinforpt.DataSource=thisDS.Tables["productiontb"].DefaultView;
proinforpt.DataBind();
accon.Close();
thisDS.Clear();
}
}
</script>


<html>
<form runat="server" method="post">
<asp:Repeater runat="server" ID="proinforpt">
 <headertemplate>
 <table width="100%" height="44" border="0" cellpadding="0" cellspacing="0">
 <asp:TemplateColumn>
  <tr align="center" valign="middle">
    <td>产品</td>
    <td>图片</td>
    <td>产地</td>
    <td>生产日期</td>
    <td>库存</td>
    <td>吨价</td>
    <td>简述</td>
  </tr>
  <tr align="center">
    <td><%# DataBinder.Eval(Container.DataItem,"name")%>cc</td>
    <td><%# DataBinder.Eval(Container.DataItem,"imgurl")%></td>
    <td><%# DataBinder.Eval(Container.DataItem,"place")%></td>
    <td><%# DataBinder.Eval(Container.DataItem,"producetime")%></td>
    <td><%# DataBinder.Eval(Container.DataItem,"kucun")%></td>
    <td><%# DataBinder.Eval(Container.DataItem,"price")%></td>
    <td><%# DataBinder.Eval(Container.DataItem,"state")%></td>
  </tr>
 </asp:TemplateColumn>
 </table>
 </headertemplate>
 </asp:Repeater>
</form>
</html>


[ 本帖最后由 guming 于 2009-11-25 16:14 编辑 ]
2 回复
#2
accpfriend2009-11-25 18:04
<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();

OleDbDataReader ckreader=theCOMD.ExecuteReader();
if(ckreader.Read())  //这里改成 when(chreader.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");
proinforpt.DataSource=thisDS.Tables["productiontb"].DefaultView;
proinforpt.DataBind();
accon.Close();
thisDS.Clear();
}
}
</script>
#3
iamblizzardb2010-03-09 19:52
没有循环,哪能显示出来啊。
while(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");
proinforpt.DataSource=thisDS.Tables["productiontb"].DefaultView;
proinforpt.DataBind();
accon.Close();
thisDS.Clear();
}
1