public partial class Index : System.Web.UI.Page
{
static DataTable dt = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
if (!dt.Columns.Contains("Id"))
{
dt.Columns.Add("Id", typeof(int));
dt.Columns.Add("Name", typeof(string));
var row1 = dt.NewRow();
row1["Id"] = 1;
row1["Name"] = "张三";
dt.Rows.Add(row1);
var row2 = dt.NewRow();
row2["Id"] = 2;
row2["Name"] = "李四";
dt.Rows.Add(row2);
}
this.rpt01.DataSource = dt;
this.rpt01.DataBind();
}
protected void rpt01_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "Del")
{
var id = e.CommandArgument.ToString();
for (int i = (dt.Rows.Count - 1); i >= 0; i--)
{
var dr = dt.Rows[i];
if (dr["Id"].ToString() == id)
{
dr.Delete();
}
}
dt.AcceptChanges();
this.rpt01.DataSource = dt;
this.rpt01.DataBind();
}
}
}