asp.net SqlDataReader绑定Repeater
作者:
asp.net SqlDataReader绑定Repeater
一直以为不可以,原来是可以的,肤浅啊!
复制代码 代码如下:
<%@ 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>