开发者

Set Default Image to asp image control

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜