主页面前台HTML代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="1217.aspx.cs" Inherits="_1217" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:Repeater ID="Repeater1" runat="server"> <HeaderTemplate> <table width="800" border="0" cellspacing="1" cellpadding="1" bgcolor="#6600FF"> <tr> <td width="120" height="30" align="center" valign="middle" bgcolor="#FFFFFF">代号</td> <td width="120" align="center" valign="middle" bgcolor="#FFFFFF">名称</td> <td width="120" align="center" valign="middle" bgcolor="#FFFFFF">价格</td> <td width="120" align="center" valign="middle" bgcolor="#FFFFFF" >产地</td> <td width="100" align="center" valign="middle" bgcolor="#FFFFFF">库存</td> <td width="100" align="center" valign="middle" bgcolor="#FFFFFF">操作</td> </tr> </HeaderTemplate> <ItemTemplate> <tr> <td width="120" height="30" align="center" valign="middle" bgcolor="#FFFFFF"><%#Eval("Ids") %></td> <td width="120" align="center" valign="middle" bgcolor="#FFFFFF"><%#Eval("Name") %></td> <td width="120" align="center" valign="middle" bgcolor="#FFFFFF"><%#Eval("Price") %></td> <td width="120" align="center" valign="middle" bgcolor="#FFFFFF" ><%#Eval("Source") %></td> <td width="100" align="center" valign="middle" bgcolor="#FFFFFF"><%#Eval("Numbers") %></td> <td width="100" align="center" valign="middle" bgcolor="#FFFFFF"><a href="Delete.aspx?ids=<%#Eval("ids") %>">删除</a> <a href="Update.aspx?ids=<%#Eval("ids") %>">修改</a></td> </tr> </ItemTemplate> <FooterTemplate> </table> </FooterTemplate> </asp:Repeater> </div> <br /> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="增加" /> </form> </body> </html>
后台C#代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _1217 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
TestDataContext context = new TestDataContext();
//绑定数据
Repeater1.DataSource = context.Fruit;
Repeater1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
//增加跳转页面
Response.Redirect("Insert.aspx");
}
}