图片:<asp:FileUpload ID="myFile"
onpropertychange="document.all.imgID1.src='file:///'+this.value"
runat="server" />
<br /><asp:Image ID="imgID1" runat="Server" />代码能够在上传图片图片时先预览图片, 但是不上传时,imgID1显示就是个“X”,不想让imgID1显示出来,只有onpropertychange事件触发时再显示应该怎么做,默认让imgID1的Visible="false",onpropertychange里让Visible="true",是这样吗,代码应该怎么写
onpropertychange="document.all.imgID1.src='file:///'+this.value"
runat="server" />
<br /><asp:Image ID="imgID1" runat="Server" />代码能够在上传图片图片时先预览图片, 但是不上传时,imgID1显示就是个“X”,不想让imgID1显示出来,只有onpropertychange事件触发时再显示应该怎么做,默认让imgID1的Visible="false",onpropertychange里让Visible="true",是这样吗,代码应该怎么写
用个if---else来判断,
如果你图片上传成功,if(dr.Read()) //灵感是这样的,你回去在去试试看。我现在在网吧,如果你还有问题我就把我做的项目的例子给你看看!
{
imgae1.values="true"
}
else
{ image1.values="false"
}
这是源码里的:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="profabu.aspx.cs" Inherits="后台管理_高级管理员_profabu" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>产品发布信息</title>
<link href="profabu.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function ShowHide()
{
if(document.getElementById('file1').value)
{
document.getElementById('Image1').style.display = "block";
document.getElementById('Image1').src = document.getElementById('file1').value;
}
else
{
document.getElementById('Image1').style.display = "none";
}
setTimeout("ShowHide()",1000);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div id="table" style ="padding: 0px;
height: 600px;
width: 700px;
margin-top: 0px;
margin-right: auto;
margin-bottom: 0px;
margin-left: auto;
background-image: url(%E7%95%8C%E9%9D%A2%E5%9B%BE%E7%89%87/bg.jpg);
background-repeat: no-repeat;
background-position: center;">
<div> <table border="0" cellpadding="0" cellspacing="0" style="width:560px; height:500px">
<tr>
<td colspan="2" style="height: 7px">
<strong><span style="color: #ffffff">产品发布:</span></strong></td>
</tr>
<tr>
<td style="width: 177px; height: 56px; text-align: center">
<span style="color: #ffffff">
产品名称:</span></td>
<td style="width: 493px; height: 56px">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 177px; height: 105px; text-align: center">
<span style="color: #ffffff">
产品描述:</span></td>
<td style="width: 493px; height: 105px">
<asp:TextBox ID="TextBox2" runat="server" Height="219px" TextMode="MultiLine" Width="443px"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 177px; text-align: center">
<span style="color: #ffffff">
产品展示:</span></td>
<td style="width: 493px">
<asp:Image ID="Image1" runat="server" Height="153px" Width="156px" /></td>
</tr>
<tr>
<td style="width: 177px; height: 41px">
<asp:Button ID="Button1" runat="server" Text="提交" OnClick="Button1_Click" /></td>
<td style="width: 493px; height: 41px">
<input id="File1" runat="server" type="file" onclick="ShowHide()"/></td>
</tr>
</table>
</div>
</div>
</form>
</body>
</html>
这是后天里的代码:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class 后台管理_高级管理员_profabu : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void Button1_Click(object sender, EventArgs e)
{
HttpPostedFile feifei = File1.PostedFile;
string fullname = feifei.FileName;
int index = fullname.LastIndexOf("\\");
string name = fullname.Substring(index + 1);
string str = Server.MapPath("image");
feifei.SaveAs(str + "\\" + name); SqlConnection con = new SqlConnection("server=.;uid=sa;pwd=;database=futian");
con.Open();
SqlCommand com = new SqlCommand("insert into profabu values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + name + "')", con); if (com.ExecuteNonQuery() > 0)
{
Response.Write("<script>alert('上传成功!')</script>");
}
else
{
Response.Write("<script>alert('上传失败!')</script>");
}
}
}
有什么疑惑的地方我很高兴为你效劳!