日期:2014-05-17  浏览次数:20497 次

Repeater不能显示问题,很急!求大家帮忙
.aspx中

<asp:repeater ID="repeater1" runat="server" 
  onitemcommand="repeater1_ItemCommand" >
  <headertemplate>
  <table class="style12">
  </headertemplate>
  <itemtemplate>
  <font color="black">
  <%#DataBinder.Eval(Container.DataItem,"ID") %>
  <a href="default2.aspx?id=<%#DataBinder.Eval(Container.DataItem,"ID")%>" target="_blank"><%#DataBinder.Eval(Container.DataItem,"新闻标题") %></a>  
  <%#DataBinder.Eval(Container.DataItem,"发布时间") %>
  </font>
  </itemtemplate>
  <FooterTemplate>
  </table>
  </FooterTemplate>
  </asp:repeater>

.cs中

 protected void Page_Load(object sender, EventArgs e)
  {
  DataBind();
  }

  #region
  public new void DataBind()
  {
  string connsql = @"data source=HONG-PC\SA;database=wz;uid=sa;password=sa1010";
  string sql = "select top 10 ID,新闻标题,发布时间 from 新闻表 where 栏目名称='新闻资讯' order by 发布时间 desc";
  SqlConnection conn = new SqlConnection(connsql);
  conn.Open();
  SqlDataAdapter adapter = new SqlDataAdapter(sql, conn);
  try
  {
  DataSet ds = new DataSet();
  adapter.Fill(ds, "table");
  repeater1.DataSource = ds.Tables["table"].DefaultView;
  repeater1.DataBind();
  // ds.Clear();
  }
  catch (SqlException ex)
  {
  Response.Write(ex.ToString());
  }
}

哪里有问题呢?运行时候没有repeater出现
帮我看一下,多谢了,很着急

------解决方案--------------------
你怎么方法还加了一个new,用在这里不合适,去掉

重新改造一下:
C# code

C# code
protected void Page_Load(object sender, EventArgs e)
{
   if(!IsPostBack)
   {
     DataBind();
   }
}

#region
public void DataBind()
{
  string connsql = @"data source=HONG-PC\SA;database=wz;uid=sa;password=sa1010";
  string sql = "select top 10 ID,新闻标题,发布时间 from 新闻表 where 栏目名称='新闻资讯' order by 发布时间 desc";
  SqlConnection conn = new SqlConnection(connsql);
  conn.Open();
  SqlDataAdapter adapter = new SqlDataAdapter(sql, conn);
  try
  {
      DataSet ds = new DataSet();
      adapter.Fill(ds);
      repeater1.DataSource = ds;
      repeater1.DataBind();

  }
  catch (SqlException ex)
  {
      Response.Write(ex.ToString());
  }
}

------解决方案--------------------
<%#DateTime.ParseExact(Eval("发布时间").ToString(),"yyyy/M/d H:mm:ss",null).ToString("yy-MM-dd") %>