代码改变世界

怎么在ASp.net中实现图片上传

2009-03-14 16:01  苏飞  阅读(884)  评论(0编辑  收藏  举报

阅读全文http://www.cckan.net/forum.php?mod=viewthread&tid=32

try
        {
            //((Image)gvGradeUser.FindControl(ImageGrade)).ImageUrl.ToString().Trim();
            //根据等级的编修改
            int enbale = 0;
            if (ddlStart.Text.ToString().Trim() == "正常")
            {
                enbale = 0;
            }
            else
            {
                enbale = 1;
            }
            //图片存在时
            if (FtxtFlileName.HasFile)
            {
                FtxtFlileName.SaveAs(Server.MapPath("../GradeImage/") + FtxtFlileName.FileName.ToString().Trim());
                if (objCusGradelevelService.SetOneGradelevelInfo(Convert.ToInt32(lblcode.Text.ToString().Trim()), txtName.Text.ToString().Trim(), Convert.ToInt32(txtJiFenFanWei.Text.ToString().Trim()), enbale, "~/PersonnelManagement/GradeImage/" + FtxtFlileName.FileName.ToString().Trim(), txtText.Text.ToString().Trim()))
                {
                    lblMessage.Visible = true;
                    lblMessage.Text = "修改成功";

                }
                else
                {
                    lblMessage.Visible = true;
                    lblMessage.Text = "修改失败";
                }

            }
            //图片不存在时
            else
            {
                if (objCusGradelevelService.SetOneGradelevelInfoNoimage(Convert.ToInt32(lblcode.Text.ToString().Trim()), txtName.Text.ToString().Trim(), Convert.ToInt32(txtJiFenFanWei.Text.ToString().Trim()), enbale, txtText.Text.ToString().Trim()))
                {
                    lblMessage.Visible = true;
                    lblMessage.Text = "修改成功";
                }
                else
                {
                    lblMessage.Visible = true;
                    lblMessage.Text = "修改失败";
                }
            }
            dt_GradeUser = objCusGradelevelService.GetAllGradelevelInfo();
            dtGradeUser();
            btnAdd.Visible = true;
            btnClearUpdate.Visible = false;
            btnUpdate.Visible = false;
        }
        catch (Exception)
        {
            lblMessage.Visible = true;
            lblMessage.Text = "修改失败";
        }