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萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章