<%@ page language="VB" debug="true" %>
<%@import namespace="System.Data.SqlClient"%>
<%@import namespace="System.Data"%>
<html>
<head>
<title>Repeater控件的使用</title>
<script runat="server">
  Dim Dt As New DataTable()
  Dim Dv As DataView  Sub Page_Load(Sender As Object,E As EventArgs)
    If Not IsPostBack Then
      Dim cnn As SqlConnection
      Dim cmd As SqlCommand
      Dim dap As SqlDataAdapter
      Dim dst As DataSet
      Dim dtb As DataTable
      Dim drow As DataRow
      cnn = New SqlConnection("server=tmd;uid=sa;pwd=sa;database=NorthWind;")
      cnn.Open()
      cmd = New SqlCommand("select * from Categories", cnn)
      dap = New SqlDataAdapter(cmd)
      dst = New DataSet
      dap.Fill(dst, "Categories")
      theRepeater.DataSource = dst.Tables("Categories")
      theRepeater.databind()
    End If
  End Sub
 
</script>
</head>
<body>
  <h2 align="center">Repeater控件的使用<hr></h2>
  <form runat="server">
    <Center>
<asp:Repeater id="theRepeater" Runat="Server">
  <HeaderTemplate>
    <Table width="80%" border="0">
    <tr>
      <th height="30" valign="top">CategoryID</th>
      <th height="30" valign="top">CategoryName</th>
      <th height="30" valign="top">Description</th>
    </tr>
  </HeaderTemplate>
  <ItemTemplate>
    <tr>
    <td align="center"><%# Container.DataItem("CategoryID") %></td>
    <td align="center"><%# Container.DataItem("CategoryName") %></td>
    <td><%# Container.DataItem("Description") %></td>
    </tr>
  </ItemTemplate>
  <AlternatingItemTemplate>
    <tr>
    <td align="center" bgcolor="#ffcc00"><%# Container.DataItem("CategoryID") %></td>
    <td align="center" bgcolor="#ffcc00"><%# Container.DataItem("CategoryName") %></td>
    <td bgcolor="#ffcc00"><%# Container.DataItem("Description") %></td>
    </tr>
  </AlternatingItemTemplate>
  <SeparatorTemplate>
    <tr>
    <td height="1" colspan="3"><hr></td>
    </tr>
  </SeparatorTemplate>
  <FooterTemplate>
    </table>
  </FooterTemplate>
</asp:Repeater>
    </Center>
  </form>
</body>

解决方案 »

  1.   

    用rapeater控件。会用datalist或是gridview吗?不过分页要自己写 不像GridView自带分页。
      

  2.   

    我觉得只要是不完成不了功能,一般新手就可以适用sqldatasoure很方便的。配置好了后,直接绑定datalist或gridview
      

  3.   

    我以前一直都是用dridview但是现在要显示的记录用一条select 查询不出来.要加工,比如"同期比率"列,,,,只能弄2个数据源然后来计算..这种也能绑定到gridview????
      

  4.   

    谢谢   wxylvmnn(答对基本靠蒙) 另外请教一个问题..如果我的数据不能够一条select查询出来.而是必须要2条select呢
    比如  "完成计划比率"列,就来自2个表"完成表""计划表".这样的话Repeater只能绑定一个数据源啊????