gpt4 book ai didi

c# - 如何要求确认删除 list 项目?

转载 作者:行者123 更新时间:2023-11-30 18:20:38 25 4
gpt4 key购买 nike

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

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);
}
}

这是删除按钮事件代码。

最佳答案

你只需要这样写

<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>

关于c# - 如何要求确认删除 list 项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12109095/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com