前臺:
<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();
}