gpt4 book ai didi

c# - 抛出新的 ArgumentException

转载 作者:太空宇宙 更新时间:2023-11-03 13:02:33 24 4
gpt4 key购买 nike

在我的代码中,我怎样才能显示弹出的警告框?我试图重播抛出新的参数异常并添加 Response.Write("alert('NOT Successful');");但它表明我在附近有语法错误”)”。如果您知道,请帮助我。在此先感谢您。

   if (!IsPostBack)
{

if (Page.Request.QueryString["hasProducts"].Equals("true"))
{
ArrayList al = Session["SelectedProducts"] as ArrayList;

if (al == null)
throw new ArgumentException("A product list is required.");


if (al.Count < 1)
throw new ArgumentException("No products selected");


string inStatement = string.Empty;
int len = al.Count;
int count = 1;
foreach (string item in al)
{
inStatement = inStatement + "'" + item + "'";
if (count < len) { inStatement = inStatement + ","; }
count++;
//List<string> list = new ArrayList<string>(item.Split(','));

//item.Split(',');
}
//List<String> list = new ArrayList<String>(al.split(","));
// inStatement = inStatement.Substring(0, inStatement.Length - 2);

//Product aProd = new Product();
SqlConnection con = new SqlConnection(strcon);
SqlCommand cmd = new SqlCommand("SELECT * FROM Products WHERE Product_ID in (" + inStatement + ")", con);
SqlDataAdapter adp = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();

con.Open();
adp.Fill(ds, "Products");
cmd.ExecuteNonQuery();
con.Close();
// GridView1.DataSource = ds;
//GridView1.DataBind();
DataList1.DataSource = ds;
DataList1.DataBind();

}
}

最佳答案

使用RegisterStartUpScript将 javascript 添加到您的页面

string message = "alert('NOT Successful');";
this.ClientScript.RegisterStartupScript(this.GetType(),"myAlert",message,true);

关于c# - 抛出新的 ArgumentException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31932699/

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