asp.net Repeater ItemCommand-后端代码

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();
        }
    }
}
上一篇:ARMS 用户体验监控正式发布原生鸿蒙应用 SDK-背景


下一篇:SpringEvent 解决 WebUploader 大文件上传解耦问题