如何要求确认删除清单项目?

时间:2012-08-24 12:04:09

标签: c# javascript asp.net

我有一些动态生成的清单项目。当用户删除它们时,应出现确认框。我怎么能这样做?

protected void btndelete_Click(object sender, EventArgs e)
        {
            try
            {
                string conn = ConfigurationManager.ConnectionStrings["sqlconn"].ConnectionString;
                SqlConnection con = new SqlConnection(conn);
                con.Open();
            check:
                if (CheckBoxList1.SelectedItem != null)
                {
                    foreach (ListItem l in CheckBoxList1.Items)
                    {
                        if (l.Selected)
                        {
                            SqlCommand cmd = new SqlCommand("Drop Table " + l, con);
                            cmd.ExecuteNonQuery();
                            Label4.ForeColor = Color.Red;
                            Label4.Text = " PaperSet Deleted successfully";
                            CheckBoxList1.Items.Remove(l);
                            papersetlist.Items.Remove(l);
                            Psetlist.Items.Remove(l);
                            goto check;
                        }
                    }
                }
                con.Close();

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

这是删除按钮事件代码。

1 个答案:

答案 0 :(得分:2)

你只需要写这样的东西

<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False"
 CommandName="Delete" Text="Delete" 
OnClientClick="return confirm('Are you certain you want to delete this item?');"> 
 </asp:LinkButton>