Repeater实现删除功能

前台:

<td width="10%" align="center">
<asp:LinkButton ID="btnDelete" CommandName='<%#DataBinder.Eval(Container.DataItem, "fpID") %>' OnCommand="btnDelete_Click" runat="server">删除</asp:LinkButton>
 </td>

后台:

    protected void btnDelete_Click(object sender, CommandEventArgs e)
    {
        int itemId = int.Parse(e.CommandName);//得到需要删除的记录的编号(Id)
        string connectionString = System.Configuration.ConfigurationManager.AppSettings["Dsn"];
        SqlConnection sqlcon = new SqlConnection(connectionString);
        sqlcon.Open();
        string delSql = "delete from FixedPoint where fpID=" + itemId;//生成Sql 语句。
        SqlCommand command = new SqlCommand(delSql, sqlcon);
        SqlDataAdapter da = new SqlDataAdapter();

        da.SelectCommand = command;
        DataTable ds = new DataTable();
        da.Fill(ds);
        BindPointManage();
    }

发布了35 篇原创文章 · 获赞 18 · 访问量 13万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章