image 控件怎么绑定数据库中图片地址?
我做了个图片上传,传上去后,可以显示出来,但是刷新后又显示不了了,应该是没有和image绑定,那怎么和image控件绑定??图片已经传上去了,路径也存在SQL数据库中了。

解决方案 »

  1.   

    如果是单个,使用Image1.ImageUrl = "path",如果多个使用GridView等控件即可
      

  2.   

    Image1.ImageUrl = "path",
    那再次打开网页的时候图片又没了,,
    那用gridview怎么用,我刚刚学。
      

  3.   

    Image1.ImageUrl = "path.aspx?id=***",
    path.aspx直接读出图片就可以了
      

  4.   

    你参考下吧  
     
      protected void Page_Load(object sender, EventArgs e)
        {
            //连接数据库的第一种方法
            SqlConnection myConnection = new SqlConnection(ConfigurationManager.AppSettings["Lw_SqlConnectString"]);        //连接数据库的第二种方法
            //SqlConnection myConnection = new SqlConnection("Data Source=.;Initial Catalog=Tcis_shrl;User Id=sa;Password=;");
            if (Session["id"] == null)
            {        }
            else
            {
                string sql = "Select PersonImage from Person Where PersonID=";
                SqlCommand myCommand = new SqlCommand(sql + Session["id"].ToString().Trim(), myConnection);
                
                try
                {
                    myConnection.Open();
                    SqlDataReader myDataReader;
                    myDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
                    if (myDataReader.Read())
                    {
                        Response.Clear();                   
                      //  Response.ContentType = "image/pjpeg";//可有可无
                        Response.BinaryWrite((byte[])myDataReader["PersonImage"]);
                    }
                    myConnection.Close();
                }
                catch (SqlException SQLexc)
                {
                     Response.Write(SQLexc);
                }
                Response.End();
            }
        }
    }