日期:2014-05-18 浏览次数:20547 次
<asp:image id="image1" runat="server" ImageUrl=' <%# Eval("imageUrl")%>' Visible=' <%# Eval("imageUrl")!=System.DBNull.Value %>' />
------解决方案--------------------
private void DataList1_ItemCreated(object sender, System.Web.UI.WebControls.DataListItemEventArgs e) { if(e.Item.ItemType==ListItemType.Item || e.Item.ItemType==ListItemType.AlternatingItem) { System.Web.UI.WebControls.Image img1=e.Item.FindControl("Image1"); if(img1.ImageUrl.Equals("")) { img1.Visible=false; } } }
------解决方案--------------------
private void DataList1_ItemCreated(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
{
if(e.Item.ItemType==ListItemType.Item || e.Item.ItemType==ListItemType.AlternatingItem)
{
System.Web.UI.WebControls.Image img1=e.Item.FindControl("Image1");
img1.Attributes.Add("onerror","默认图片路径");
}
}
这样你只要有一张默认图片就可以,不需要上传的
------解决方案--------------------
<asp:Image onerror="this.style.visibility='hidden';"/>