首页 > 编程 > .NET > 正文

asp.net SqlDataReader绑定Repeater

2020-01-18 01:19:58
字体:
来源:转载
供稿:网友

一直以为不可以,原来是可以的,肤浅啊!
复制代码 代码如下:

<%@ 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>
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表