马上加入IBC程序猿 各种源码随意下,各种教程随便看! 注册 每日签到 加入编程讨论群

C#教程 ASP.NET教程 C#视频教程程序源码享受不尽 C#技术求助 ASP.NET技术求助

【源码下载】 社群合作 申请版主 程序开发 【远程协助】 每天乐一乐 每日签到 【承接外包项目】 面试-葵花宝典下载

官方一群:

官方二群:

Repeater控件的用法

[复制链接]
查看7184 | 回复0 | 2012-12-2 14:27:39 | 显示全部楼层 |阅读模式
Repeater是一个绑定数据源自由更改样式的控件,他的优点就在于他不会再客户端生成多余的代码。
  1. 在 .aspx 页面中创建一个 Repeater 控件。<HeaderTemplate> 元素中的内容在输出中仅出现一次,而 <ItemTemplate> 元素的内容会对应 DataSet 中的 "record" 重复出现,最后,<FooterTemplate>的内容在输出中仅出现一次。
  2. 在 <ItemTemplate>元素后添加 <AlternatingItemTemplate>元素,这样就可以描述交替行的外观了。
  3. <SeparatorTemplate>元素能够用于描述每个记录之间的分隔符。
  4. 示例:
  5. <form runat="server">
  6. <asp:Repeater id="cdcatalog" runat="server">  
  7. <HeaderTemplate>
  8. <table border="1" width="100%">
  9. <tr>
  10. <th>Title</th>
  11. <th>Artist</th>
  12. <th>Country</th>
  13. <th>Company</th>
  14. <th>Price</th>
  15. <th>Year</th> </tr>
  16. </HeaderTemplate>
  17. <ItemTemplate>
  18. <tr> <td><%#Container.DataItem("title")%></td>
  19. <td><%#Container.DataItem("artist")%></td>
  20. <td><%#Container.DataItem("country")%></td>
  21. <td><%#Container.DataItem("company")%></td>
  22. <td><%#Container.DataItem("price")%></td>
  23. <td><%#Container.DataItem("year")%></td> </tr>
  24. </ItemTemplate>  <AlternatingItemTemplate>
  25. <tr bgcolor="#e8e8e8">  <td>
  26. <%#Container.DataItem("title")%></td>
  27. <td><%#Container.DataItem("artist")%></td>
  28. <td><%#Container.DataItem("country")%></td>
  29. <td><%#Container.DataItem("company")%></td>
  30. <td>
  31. <%#Container.DataItem("price")%></td>
  32. <td><%#Container.DataItem("year")%>
  33. </td>
  34. </tr>
  35. </AlternatingItemTemplate>
  36. <SeparatorTemplate>
  37. <tr>
  38. <td colspan="6"><hr /></td> </tr> </SeparatorTemplate>  
  39. <FooterTemplate>
  40. </table>
  41. </FooterTemplate>
  42.   </asp:Repeater>
复制代码
C#论坛 www.ibcibc.com IBC编程社区
C#
C#论坛
IBC编程社区
*滑块验证:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则