首页 > 解决方案 > asp.net sql删除datatable生成的一行

问题描述

在此处输入图像描述

我想创建一个删除按钮,获取旁边的 id

我获取数据的方法是这样的一个按钮生成创建图片

protected void btnSelect_Click(object sender, EventArgs e)
{
    try /* Select After Validations*/
    {
        using (NpgsqlConnection connection = new NpgsqlConnection())
        {
            connection.ConnectionString = ConfigurationManager.ConnectionStrings["SHOT"].ToString();
            connection.Open();
            NpgsqlCommand cmd = new NpgsqlCommand();
            cmd.Connection = connection;
            cmd.CommandText = "Select * from shot_assessment";
            cmd.CommandType = CommandType.Text;
            NpgsqlDataAdapter da = new NpgsqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            cmd.Dispose();
            connection.Close();

            GridView1.DataSource = dt;
            GridView1.DataBind();
        }
    }
    catch (Exception ex) { }
}

html代码为:`

          <asp:TemplateField HeaderText="Delete">
               <ItemTemplate>
                   <asp:LinkButton ID="LinkButton1" runat="server" CommandName="delete">Delete</asp:LinkButton>
               </ItemTemplate>
           </asp:TemplateField></Columns></asp:GridView>  `

标签: sqlasp.netpostgresql

解决方案


推荐阅读