标题:asp.net 上传图片并用img控件局部刷新显示
取消只看楼主
小勇哥
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2013-8-29
结帖率:0
已结贴  问题点数:20 回复次数:0 
asp.net 上传图片并用img控件局部刷新显示
用到了一般处理程序(ashx)和aspx之间的传值
上传控件。cs:
using System;
using System.Collections.Generic;
using System.Linq;
using
using
using System.Web;
using System.Web.Services;
using GoldenEasy.YangclGecmp.Data;
using System.Data.SqlClient;
using GECMP_IDAL;

namespace GECMP.Ajax
{
    public partial class UploadFile : System.Web.UI.Page
    {
        DBOperator dbo = DBOperatorFactory.GetDBOperator();
        protected void Page_Load(object sender, EventArgs e)
        {
            HttpPostedFile file = Request.Files["Filedata"];
            string uploadPath =
                HttpContext.Current.Server.MapPath(Request["folder"]) + "\\";

            if (file != null)
            {
                if (!Directory.Exists(uploadPath))
                {
                    Directory.CreateDirectory(uploadPath);
                }
                file.SaveAs(uploadPath + file.FileName);
                //下面这句代码缺少的话,上传成功后上传队列的显示不会自动消失
                string Path = "\\UploadFile\\";
                string ImgName = file.FileName;

                Session["ImageName"]= ImgName;        
                string ImagePath = Path + ImgName;
                Session["ImgPath"] = ImagePath;

              
                //原有的东西,和数据库操作没关系
               Response.Write("1");
            }
            else
            {
               Response.Write("0");
            }
        }
    }
}


页面的保存在一般处理程序中处理:
    para[38] = "0.00";
                para[39] = "0";
                para[40] = context.Request["UnitName.id"];

                switch (Title)
                {
                    case "add":
                        OBJ.ExecProcReInt("pt_Insert_EstateReg", para);
                        string sql = "insert into HousePhoto(PriCode,ImgName,Note) Values('" + HouseCode + "','" + Imgname + "','" + ImgPath + "')";
                        OBJ.ExecSQLReInt(sql);
                        context.Response.Write(success("", "HouseApply"));
                        context.Response.Redirect("//HouseRegister/RegisterApply.aspx?s1=" + HouseCode + "");
                        break;

怎样达到我的效果啊,上传同时img局部刷新显示图片。

客户界面:
                <td class="right_bg" colspan="5">
                    <a href="../Control/UploadFile.aspx" maxable="false" width="550" target="dialog"><span
                        style="color: Red;">添加附件</span></a>
                </td>
            </tr>
            <tr>
                <td class="right_bg" colspan="6" style="height: 100px;">
                    <p>
                        比例:</p>
                    &nbsp;&nbsp;&nbsp;<asp:Image ID="D21" runat="server" ImageUrl="\\UploadFile\Tulips.jpg"   style="width: 900px; height: 220px;" /><br />
                </td>
            </tr>
        </table>
界面。cs:
        /// 显示图片
        /// </summary>
        public void ShowImage()
        {
            string HouseCode = Request.QueryString["s1"].ToString();
            //string sql = "SELECT Note FROM HousePhoto where PriCode='HouseCode'";
            string sql = "SELECT Note FROM HousePhoto where PriCode='1'";
            SqlConnection con = new SqlConnection("Data Source=192.168.1.18;Initial Catalog=yjoa;User ID=sa;pwd=123;");
            con.Open();


            //SqlCommand cmd = new SqlCommand(sql, con);
            SqlDataAdapter sda = new SqlDataAdapter(sql, con);
            DataSet ds = new DataSet();

            sda.Fill(ds);
            //this.imgUrl = ds.ToString();
            this.D21.ImageUrl = ds.Tables[0].Rows[0]["Note"].ToString();

            //string wpath = ds.Tables[0].Rows[0]["wpath"].ToString();
            //Image1.ImageUrl = wpath;
            //Label3.Text = wpath;
            con.Close();//关闭连接
            con.Dispose();
        }

搜索更多相关主题的帖子: public 图片 
2013-08-29 09:07



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-419787-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.228353 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved