如果是把image的ImageUrl直接写死就可以显示出图片,但是如果从数据库读出地址来就不行!
弹出层的代码如下<style type="text/css">
<!--
*{font-size:12px;font-family:Verdana, Geneva, sans-serif;line-height:14px}
a{color:#039}
a:hover{color:#f60}
.pop{position:absolute;left:40%;top:40%;width:300px;height:100px;background:#eee;border:1px solid #ccc}
.pop_head{position:relative;height:20px;background:#ccc}
.pop_head a{position:absolute;right:8px;line-height:20px;color:#000;text-decoration:none}
.pop_head a:hover{color:#f60;text-decoration:none}
.pop_body{padding:8px}
-->
</style>
</head>
<body>
<form id="form1" runat="server">
<!--首先设置一个层:-->
<div id="pop" class="pop" style="display:none">
<div class="pop_head"><a href="javascript:void(0);" onclick="hide('pop')">关闭</a></div>
<div class="pop_body"><asp:Image ID="Image1" runat="server" /></div>
</div>
<script type="text/javascript">
function show(o){
var o = document.getElementById(o);
o.style.display = "";
}
function hide(o){
var o = document.getElementById(o);
o.style.display = "none";
}
</script><asp:Button ID="Button1" runat="server" Text="显示图片" OnClientClick="show('pop')"
onclick="Button1_Click" />后台读出url地址的代码--点击显示图片的按钮
DataRowView drv = dt1.Tables[0].DefaultView[0];
Image1.ImageUrl = Convert.ToString(drv.Row["Pro_Pic"]);
弹出层的代码如下<style type="text/css">
<!--
*{font-size:12px;font-family:Verdana, Geneva, sans-serif;line-height:14px}
a{color:#039}
a:hover{color:#f60}
.pop{position:absolute;left:40%;top:40%;width:300px;height:100px;background:#eee;border:1px solid #ccc}
.pop_head{position:relative;height:20px;background:#ccc}
.pop_head a{position:absolute;right:8px;line-height:20px;color:#000;text-decoration:none}
.pop_head a:hover{color:#f60;text-decoration:none}
.pop_body{padding:8px}
-->
</style>
</head>
<body>
<form id="form1" runat="server">
<!--首先设置一个层:-->
<div id="pop" class="pop" style="display:none">
<div class="pop_head"><a href="javascript:void(0);" onclick="hide('pop')">关闭</a></div>
<div class="pop_body"><asp:Image ID="Image1" runat="server" /></div>
</div>
<script type="text/javascript">
function show(o){
var o = document.getElementById(o);
o.style.display = "";
}
function hide(o){
var o = document.getElementById(o);
o.style.display = "none";
}
</script><asp:Button ID="Button1" runat="server" Text="显示图片" OnClientClick="show('pop')"
onclick="Button1_Click" />后台读出url地址的代码--点击显示图片的按钮
DataRowView drv = dt1.Tables[0].DefaultView[0];
Image1.ImageUrl = Convert.ToString(drv.Row["Pro_Pic"]);
<div class="pop_head"><a href="javascript:void(0);" onclick="hide('pop')">关闭</a></div>
<div class="pop_body"><asp:Image ID="Image1" runat="server" /></div>
</div>--点击显示图片的按钮
DataRowView drv = dt1.Tables[0].DefaultView[0];
Image1.ImageUrl = Convert.ToString(drv.Row["Pro_Pic"]);
pop.Attributes.Add("style", "display:block");提交后 OnClientClick="show('pop')"没用,去掉
2 有可能是路径问题。Image1.ImageUrl ="../"+ Convert.ToString(drv.Row["Pro_Pic"]);或者把"../"换成"~/"试一下看看
function show(o){
var o = document.getElementById(o);
o.style.display = "";
return false;
}
代码修改成这样 看看
<asp:Button ID="Button1" runat="server" Text="显示图片" OnClientClick="show('pop')"
onclick="Button1_Click" />
你这里点击按纽,首先触发的是客户端事件,即显示层,这时层是显示了但页面还没回发还没有触发服务器羰的按纽事件,图片的地址当然还是空的
整个思路有问题
一、首行在Page_load事件里就直接把图片地址取出来,在按纽里只触发客户端事件来显示层
二、或者通过ajax方式在按纽点击事件中取出图片地址
1.如果这个值是已经在内存中的datatable中获取,是否可以先存在在前台,用隐藏域来保持图片地址。
2.可以采用动态添加img控件的方式。例如在一个DIV中用innerText属性来添加图片<img>标签。