做个留言本,回复要是没数据的就不显示怎么弄。Panel 不知道怎么控制。book.aspx
<asp:Repeater ID="list" runat="server">  
<itemtemplate>
 <table width="100%" border="1">
       <tr>
         <td width="14%">用户</td>
         <td width="32%"><%# DataBinder.Eval(Container.DataItem, "username")%></td>
         <td width="14%">发言时间</td>
         <td width="40%"><%# DataBinder.Eval(Container.DataItem, "uptime")%></td>
       </tr>
       <tr>
         <td>留言内容</td>
         <td colspan="3"><%# DataBinder.Eval(Container.DataItem, "body")%></td>
       </tr>   
     </table> <asp:Panel ID="viewer" runat="server">
       <table width="101%" border="1">
         <tr>
           <td width="14%">回复内容</td>
           <td width="86%"><%# DataBinder.Eval(Container.DataItem, "restore")%></td>
         </tr>
       </table> 
</asp:Panel>
    
   </itemtemplate>
</asp:Repeater>book.aspx.cs

解决方案 »

  1.   

    在ItemDataBound事件里面判断数据,如果为空,就FindControl("viewer")让他隐藏起来~~
      

  2.   

    ItemDataBound怎么用?我是
    list.DataSource=conn.GetDataTable(sql);
    list.DataBind(); 
    把数据绑定的。不知道怎么判断restore字段是空。能不能给出相应的代码谢谢
      

  3.   

    1:在Repeater的ItemDataBound事件中判断: DataRowView drv = (DataRowView)e.Item.DataItem;
     if(drv.Row["restore"].ToString() == ""||drv.Row["restore"]==null)
     {
        Panel a=(Panel)e.Item.FindControl("viewer");
        a.Visible=false;
    }2: 在HTML页面上根据<%# DataBinder.Eval(Container.DataItem, "restore")%>的值直接对Panel进行控制。
      

  4.   

    <asp:Panel ID="viewer" runat="server" Visible='<%# DataBinder.Eval(Container.DataItem, "restore") != System.DBNull.Value %>'> 
          <table width="101%" border="1"> 
            <tr> 
              <td width="14%">回复内容 </td> 
              <td width="86%"> <%# (DataBinder.Eval(Container.DataItem, "restore") == System.DBNull.Value ? string.Empty : DataBinder.Eval(Container.DataItem, "restore"))%> </td> 
            </tr> 
          </table> 
    </asp:Panel> 
      

  5.   

    回帖的方法2,用楼上高歌的方法:
    将Panel的Visible属性设置为:' <%# DataBinder.Eval(Container.DataItem, "restore").ToString() != "" %>'
      

  6.   

    1楼正解   1楼是指 Repeater的ItemDataBound事件 
      

  7.   

    <asp:Panel ID="viewer" runat="server" Visible=' <%# DataBinder.Eval(Container.DataItem, "restore") != System.DBNull.Value %>'> 
          <table width="101%" border="1"> 
            <tr> 
              <td width="14%">回复内容 </td> 
              <td width="86%"> <%# (DataBinder.Eval(Container.DataItem, "restore") == System.DBNull.Value ? string.Empty : DataBinder.Eval(Container.DataItem, "restore"))%> </td> 
            </tr> 
          </table> 
    </asp:Panel>