在我的代码中,我怎样才能显示弹出的警告框?我试图重播抛出新的参数异常并添加 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/