예제 #1
0
    //更新事件
    protected void DetailsViews1_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
    {
        string catId = ((DropDownList)DetailsViews1.FindControl("DropDownList1")).SelectedValue;

        e.NewValues.Add("Category", new Ep229Category {
            CatId = Int32.Parse(catId)
        });
    }
예제 #2
0
파일: Add.aspx.cs 프로젝트: moxi255/shop
    //上传图片事件
    protected void DetailsViews1_ItemInserting(object sender, DetailsViewInsertEventArgs e)
    {
        string saveDir = @"\Views\Images\";

        string appPath = Request.PhysicalApplicationPath;

        FileUpload upload = ((FileUpload)DetailsViews1.FindControl("FileUpload1"));

        e.Values.Add("Category", new Ep229Category
        {
            CatId = Int32.Parse(e.Values["CatId"].ToString())
        });
        e.Values.Remove("CatId");
        if (upload.HasFile)

        {
            int fileSize = upload.PostedFile.ContentLength;
            if (fileSize < 2100000)
            {
                string ext = System.IO.Path.GetExtension(upload.FileName);
                if ((ext == ".jpg") || (ext == ".gif"))
                {
                    string filename = DateTime.Now.Ticks.ToString() + ext;
                    string savePath = appPath + saveDir + filename;
                    upload.SaveAs(savePath);
                    e.Values.Add("ProdImage", filename);
                }
                else
                {
                    this.ClientScript.RegisterClientScriptBlock(this.GetType(),
                                                                "", "alert('添加失败上传图片扩展名必须是.jpg或.gif'); ", true);
                    e.Cancel = true;
                }
            }
            else
            {
                this.ClientScript.RegisterClientScriptBlock(this.GetType(),
                                                            "", "alert('上传文件的大小不能超过2MB'); ", true);
                e.Cancel = true;
            }
            //文件大小大约为2MB
        }
    }