string cnString = System.Configuration.ConfigurationManager.ConnectionStrings["cnString"].ConnectionString; string queryString = "select * from employees"; SqlConnection con = new SqlConnection(cnString); SqlDataAdapter adapter = new SqlDataAdapter(queryString, con); DataSet ds = new DataSet(); adapter.Fill(ds, "employees"); Repeater1.DataSource = ds.Tables["employees"]; Repeater1.DataBind();
default.aspx:
<asp:Repeater ID="Repeater1" runat="server"> <HeaderTemplate> <table> <tr> <th>ID</th> <th>Last Name</th> <th>First Name</th> <th>Hired Date</th> </tr> </HeaderTemplate> <ItemTemplate> <tr> <td><%# Eval("employeeid") %></td> <td><%# Eval("lastname") %></td> <td><%# Eval("firstname") %></td> <td><%# Eval("hiredate") %></td> </tr> </ItemTemplate> <FooterTemplate> </table> </FooterTemplate> </asp:Repeater>
沒有留言:
張貼留言