开发者

Set Default Image to asp image control

开发者 https://www.devze.com 2023-03-23 11:56 出处:网络
i need to set default image to asp.net image control as i use datalist to set image url <asp:Image ID=\"Image1\" runat=\"server\" ImageUrl=\'<%# DataBinder.Eval(Container.DataIt开发者_如何学运

i need to set default image to asp.net image control as i use datalist to set image url

<asp:Image ID="Image1" runat="server" ImageUrl='<%# DataBinder.Eval(Container.DataIt开发者_如何学运维em, "ImgPath")%>'
     AlternateText="No Pic" Width="107" Height="86" />

sometimes databinder doesn't return imgpath so i need to set default image to image Control tp show it when imgpath is null


You can do like...

ImageUrl='<%# DataBinder.Eval(Container.DataItem, "ImgPath").ToString() == "" ? 
"/Images/DefaultImage.png" : DataBinder.Eval(Container.DataItem, "ImgPath") %>'


Hard code the image url in your image control declaration and change the ImageUrl property during databinding event.


ImageUrl='<%# IIF(Not IsDBNull(Eval("ImgPath")), Eval("ImgPath"), "DefaultImage.jpg") %>'
0

精彩评论

暂无评论...
验证码 换一张
取 消