前台:
<table width="650" border="1"> <tr> <td class="tr1"> <asp:Label Text="姓名" runat="server"></asp:Label> </td> </tr> </table> <asp:Repeater ID="Repeater1" runat="server"> <ItemTemplate> <table border="1" width="650"> <tr> <td class="tr1"> <%#Eval("E_Name")%> </td> </tr> </table> </ItemTemplate> </asp:Repeater>
后台:
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
string connString = "server=.;database=ComInfo;integrated security=true";//连接字符串 SqlConnection conn = new SqlConnection(connString);//创建连接 String strsql = "select E_Name from Emp";//sql语句 SqlDataAdapter da = new SqlDataAdapter(strsql, conn); DataSet ds = new DataSet(); da.Fill(ds); this.Repeater1.DataSource = ds; this.Repeater1.DataBind();//绑定
}
}