一直以為不可以,原來是可以的,膚淺啊!
復制代碼 代碼如下:
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Data" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("server=.;database=dnt;user id=ahuinan;pwd=123;");
conn.Open();
SqlCommand cmd = new SqlCommand("select * from dnt_users", conn);
SqlDataReader dr = cmd.ExecuteReader();
rpt.DataSource = dr;
rpt.DataBind();
dr.Close();
conn.Close();
}
</script>
<html>
<head>
<title>SqlDataReader綁定Repeater</title>
</head>
<body>
<form id="form1" runat="server">
<table border="1">
<asp:Repeater ID="rpt" runat="server">
<ItemTemplate>
<tr>
<td><%#Eval("uid") %></td>
<td><%#Eval("username") %></td>
<td><%#Eval("password") %></td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
</form>
</body>
</html>