1.前台设计
2.后台
<asp:Repeater ID="Rep1" runat="server">
<HeaderTemplate>
<table width="800px">
<tr style="background-color:Red">
<td style="width:160px;">学号</td>
<td style="width:160px;">姓名</td>
<td style="width:160px;">性别</td>
<td style="width:160px;">年龄</td>
<td style="width:160px;">邮箱</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr οnmοusemοve="this.style.backgroundColor='#0099CC'" οnmοuseοut="this.style.backgroundColor=''"> <!--实现了鼠标经过时变色-->
<td><%#DataBinder.Eval(Container.DataItem,"sno") %></td>
<td><%#DataBinder.Eval(Container.DataItem,"sname") %></td>
<td><%#DataBinder.Eval(Container.DataItem,"sex") %></td>
<td><%#DataBinder.Eval(Container.DataItem,"age") %></td>
<td><%#DataBinder.Eval(Container.DataItem,"email") %></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
2.后台
public partial class MoveStyle : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Bind();
}
}
protected void Bind()
{
SqlConnection con = new SqlConnection(Connection.connection());
con.Open();
SqlCommand com = new SqlCommand("select * from student", con);
SqlDataReader dr = com.ExecuteReader();
Rep1.DataSource = dr;
Rep1.DataBind();
con.Close();
con.Dispose();
}
}