在ASP.NET里,上传显示图片
在ASP.NET(C#)中,上传图片到数据库,并显示在ASP.NET页面上求完整的代码,最好有实例...
在ASP.NET(C#)中,上传图片到数据库,并显示在ASP.NET页面上
求完整的代码,最好有实例 展开
求完整的代码,最好有实例 展开
2个回答
展开全部
是同时显示,而且上传吗?楼上的说的对!我用的是第二种方法。但是上传跟显示是两个过程没有什么联系的。
页面显示的代码:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="11-26-2.aspx.cs" Inherits="测试_11_26_2" %>
<!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 id="Head1" runat="server">
<title>Test</title>
<script language="javascript" type="text/javascript">
function PreviewImage(i)
{
var imageID = "Image"+i;
var fileID = "FileUpload"+i;
var buttonID="btnPreview"+i;
var picName = document.getElementById(fileID).value;
var array = picName.split(".");
var extendName = array[1];
extendName = extendName.toLowerCase();
if(extendName == "jpg" || extendName == "gif" )
{
document.getElementById(imageID).src=picName;
javascript:ChangeState(buttonID);
// document.getElementById(buttonID).visible="true";
}
else
{
window.alert("对不起!你选择的图片类型有误!请重新选择!");
}
}
function ChangeState(_id)
{
var oTable = document.getElementById(_id);
if(oTable.style.display == "none")
{
oTable.style.display = "";
}
else
{
oTable.style.display = "none";
}
}
function dele(j)
{
var imageID = "Image"+j;
var fileID = "FileUpload"+j;
// document.getElementById (imageID).value="";
document.getElementById (fileID).value="";
document.getElementById(imageID).src="";
// document.getElementById (fileID).value.delete();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<table>
<tr>
<td>
<asp:FileUpload ID="FileUpload1" runat="server" Width="260px" />
</td>
</tr>
<tr>
<td>
<asp:Image ID="Image1" runat="server" Height="300px" Width="400px" />
</td>
</tr>
</table>
<br />
</form>
</body>
</html>
页面显示的代码:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="11-26-2.aspx.cs" Inherits="测试_11_26_2" %>
<!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 id="Head1" runat="server">
<title>Test</title>
<script language="javascript" type="text/javascript">
function PreviewImage(i)
{
var imageID = "Image"+i;
var fileID = "FileUpload"+i;
var buttonID="btnPreview"+i;
var picName = document.getElementById(fileID).value;
var array = picName.split(".");
var extendName = array[1];
extendName = extendName.toLowerCase();
if(extendName == "jpg" || extendName == "gif" )
{
document.getElementById(imageID).src=picName;
javascript:ChangeState(buttonID);
// document.getElementById(buttonID).visible="true";
}
else
{
window.alert("对不起!你选择的图片类型有误!请重新选择!");
}
}
function ChangeState(_id)
{
var oTable = document.getElementById(_id);
if(oTable.style.display == "none")
{
oTable.style.display = "";
}
else
{
oTable.style.display = "none";
}
}
function dele(j)
{
var imageID = "Image"+j;
var fileID = "FileUpload"+j;
// document.getElementById (imageID).value="";
document.getElementById (fileID).value="";
document.getElementById(imageID).src="";
// document.getElementById (fileID).value.delete();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<table>
<tr>
<td>
<asp:FileUpload ID="FileUpload1" runat="server" Width="260px" />
</td>
</tr>
<tr>
<td>
<asp:Image ID="Image1" runat="server" Height="300px" Width="400px" />
</td>
</tr>
</table>
<br />
</form>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询