以下的写法有误,怎么写代码啊?谢谢!
if(Response.Write("<script>confirm('确要上传" + DropDownList1.Text + '年' + DropDownList2.Text + '月' + FileUpload1.FileName + "?')</script>"))
{
……
}
[此贴子已经被作者于2007-3-14 10:51:04编辑过]
[此贴子已经被作者于2007-3-14 10:51:04编辑过]
[此贴子已经被作者于2007-3-14 12:44:48编辑过]
主要是想知道如果在弹出的窗口中选择了“确定”才执行条件语句,选择“取消”就退出执行程序,这个条件语句应如何表达??有*.aspx.cs中用代码如何来判断在弹出的窗口中选择了“确定”还是选择“取消”????
[此贴子已经被作者于2007-3-14 12:51:29编辑过]
不行啊,大哥!
如果用 if(!ISPostBock) 就根本不弹出对话框;如果用 if(ISPostBock)的话,第一次单击按钮不弹出对话框,第一次之后再单击按钮才弹出对话框。怎么解决啊?谢谢!
protected void Button1_Click1(object sender, EventArgs e)
{
//Response.Write("<script>confirm('确要上传" + DropDownList1.Text + '年' + DropDownList2.Text + '月' + FileUpload1.FileName + "?')</script>");
if (!IsPostBack)
{
Button1.Attributes.Add("onclick", "javascript:return confirm('确要上传" + DropDownList1.Text + '年' + DropDownList2.Text + '月' + FileUpload1.FileName + "?');");
Boolean fileOK = false;
String path = Server.MapPath("~/files/") + DropDownList1.Text + "年/" + RadioButtonList1.Text.ToString() + "/";
if (FileUpload1.HasFile)
{
String fileExtension =
System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
String[] allowedExtensions =
{ ".xls", ".doc" }; //过滤Word和Excel文件
for (int i = 0; i < allowedExtensions.Length; i++)
{
if (fileExtension == allowedExtensions[i])
{
fileOK = true;
}
}
}
if (fileOK)
{
try
{
FileUpload1.PostedFile.SaveAs(path
+ FileUpload1.FileName);
Response.Write("<script>alert('文件上传成功!')</script>");
//Response.Write("<script>alert('" + FileUpload1.FileName + "')</script>");
}
catch (Exception ex)
{
Response.Write("<script>alert('文件上传失败!')</script>");
//Response.Write("<script>alert('" + FileUpload1.FileName + "')</script>");
}
}
else
{
Response.Write("<script>alert('不能上传这种类型的文件!')</script>");
}
SqlConnection conn2 = new SqlConnection("data source=(local);database=aaa;user=****; password=********"); //创建连接对象
SqlDataAdapter da2 = new SqlDataAdapter();
//适配器对象的查询命令
SqlCommand cmdSel = new SqlCommand("select * from mybaobiao", conn2); //创建DataAdapter(数据适配器)
da2.SelectCommand = cmdSel;
//适配器对象的更新命令
SqlCommand cmdUpdate = new SqlCommand("update mybaobiao set NIAN = @NIAN,YU=@YU,YUFENG=@YUFENG,YDBBURL=@YDBBURL,SCHBURL=@SCHBURL,GDJCTZ=@GDJCTZ,GDJCTB=@GDJCTB where ID = @ID", conn2);
SqlParameter paramID = new SqlParameter("@ID", SqlDbType.Int);
paramID.SourceColumn = "ID"; //数据值对应的字段
paramID.SourceVersion = DataRowVersion.Original; //数据值将使用初始版本的数值
cmdUpdate.Parameters.Add(paramID);
cmdUpdate.Parameters.Add("@NIAN", SqlDbType.Char, 10, "NIAN");
cmdUpdate.Parameters.Add("@YU", SqlDbType.VarChar, 50, "YU");
cmdUpdate.Parameters.Add("@YUFENG", SqlDbType.VarChar, 50, "YUFENG");
cmdUpdate.Parameters.Add("@YDBBURL", SqlDbType.VarChar, 200, "YDBBURL");
cmdUpdate.Parameters.Add("@SCHBURL", SqlDbType.VarChar, 200, "SCHBURL");
cmdUpdate.Parameters.Add("@GDJCTZ", SqlDbType.VarChar, 200, "GDJCTZ");
cmdUpdate.Parameters.Add("@GDJCTB", SqlDbType.VarChar, 200, "GDJCTB");
da2.UpdateCommand = cmdUpdate; //
//适配器对象的添加命令
SqlCommand cmdInsert = new SqlCommand("insert into mybaobiao(NIAN,YU,YUFENG,YDBBURL,SCHBURL,GDJCTZ,GDJCTB) values (@NIAN,@YU,@YUFENG,@YDBBURL,@SCHBURL,@GDJCTZ,@GDJCTB)", conn2);
cmdInsert.Parameters.Add("@ID", SqlDbType.Int, 4, "ID");
cmdUpdate.Parameters.Add("@NIAN", SqlDbType.Char, 10, "NIAN");
cmdUpdate.Parameters.Add("@YU", SqlDbType.VarChar, 50, "YU");
cmdUpdate.Parameters.Add("@YUFENG", SqlDbType.VarChar, 50, "YUFENG");
cmdUpdate.Parameters.Add("@YDBBURL", SqlDbType.VarChar, 200, "YDBBURL");
cmdUpdate.Parameters.Add("@SCHBURL", SqlDbType.VarChar, 200, "SCHBURL");
cmdUpdate.Parameters.Add("@GDJCTZ", SqlDbType.VarChar, 200, "GDJCTZ");
cmdUpdate.Parameters.Add("@GDJCTB", SqlDbType.VarChar, 200, "GDJCTB");
da2.InsertCommand = cmdInsert;
//适配器对象的删除命令
SqlCommand cmdDel = new SqlCommand("delete * from mybaobiao where ID=@ID", conn2);
SqlParameter paramDelID = new SqlParameter("@ID", SqlDbType.Int);
paramDelID.SourceColumn = "ID";
paramDelID.SourceVersion = DataRowVersion.Original;
cmdDel.Parameters.Add(paramDelID);
da2.DeleteCommand = cmdDel;
DataSet ds2 = new DataSet(); //创建DataSet(数据集)
da2.Fill(ds2, "mybaobiao"); //使用数据适配器填充数据集
GridView1.DataSource = ds2; //显示,绑定
//GridView1.DataMember = "mybaobiao";
GridView1.DataBind();
//添加数据
DataRow addrow = ds2.Tables[0].NewRow();
addrow[1] = DropDownList1.Text;
addrow[2] = DropDownList2.Text;
addrow[3] = DropDownList1.Text + "年" + DropDownList2.Text + "月";
addrow[4] = "files/" + DropDownList1.Text + "年/" + RadioButtonList1.Text.ToString() + "/" + FileUpload1.FileName;
ds2.Tables[0].Rows.Add(addrow);
GridView1.DataSource = ds2.Tables["mybaobiao"]; //显示,绑定
GridView1.DataBind();
//da2.Update(ds2, "mybaobiao");
////修改数据
//DataRow editrow = ds2.Tables["mybaobiao"].Rows[5];
////editrow.BeginEdit();
//editrow["RegionDescription"] = "北京6北京6北京6";
////editrow.EndEdit();
//GridView1.DataSource = ds2.Tables["mybaobiao"]; //显示,绑定
//GridView1.DataBind();
////da2.Update(ds2, "mybaobiao");
////删除数据
//DataRow editrow1 = ds2.Tables["mybaobiao"].Rows[3];
//editrow1.Delete();
//GridView1.DataSource = ds2; //显示,绑定
//GridView1.DataBind();
////da2.Update(ds2,"Region")
}
}
不可能哦
每次点击BUTTION后都会弹出啊,你是第一次没出,其它都出了?