Image is not in ImageButton asp.net
I use ListView in asp.net. I get data from provider table. According providerId image is stored in same folder(like 1.jpg,2.jpg
).
I want to display image according to providerID.
But Image is not showing. but when i use simple html img control then image is showing.
What should i do for show image in ImageButton.
<asp:ListView DataSourceID="ObjectDataSource1" ItemPlaceholderID="dd" ID="ddlprovider"
runat="server">
<LayoutTemplate>
<ul>
<asp:PlaceHolder ID="dd" runat="server"/>
</ul>
</LayoutTemplate>
<ItemTemplate>
<asp:ImageButton runat="server" ImageUrl='<%#Eval("ProviderI开发者_开发百科D") %>.jpg' ID="imgButton" />//Not work
<asp:LinkButton runat="server" CommandArgument='<%#Eval("ProviderID") %>'/>
</ItemTemplate>
</asp:ListView>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
DeleteMethod="Delete" InsertMethod="Insert"
OldValuesParameterFormatString="original_{0}" SelectMethod="FetchAll"
TypeName="mogile.MidTier.DAL.ProviderController" UpdateMethod="Update">
</asp:ObjectDataSource>
You shouldn't put code breaks in an attribute with a string at the end like that.
Try changing the line of code to:
<asp:ImageButton runat="server" ImageUrl='<%# string.format("{0}.jpg", Eval("ProviderID")) %>' ID="imgButton" />
EDIT: If you wish to display a default image if this one doesn't exist you'll need to modify the code to:
<asp:ImageButton runat="server" ImageUrl='<%# GetImageURL(Eval("ProviderID")) %>' ID="imgButton" />
Function GetImageURL(ProviderID as Integer) as String
Dim ImageFileName as string = string.format("[image path here]/{0}", ProviderID)
If Not File.Exists(server.mappath(imagefilename)) then imagefilename = "[default image path here]
Return ImageFileName
End Function
精彩评论