How to show Image In GridView?
I am working on a live project in which I have to prepare an Admin interface. In this Admin Interface the Admin of the website can manipulate data and user images. Problem is that I am unable to show the image because I have s开发者_如何学JAVAaved image path in database in respect to associate userid. I am also able to show data but I don't know how to show data so that the Admin can make changes upon it.
To display the image you will probably need to make the directory that you are storing your images in a Virtual Directory in IIS. Once you do this you should be able to create a URL based on the file name. Example:
if your file path is C:\UserImages\1234.jpg
You will need to make UserImages a Virtual Directory, then in your code do something like this:
string baseImgUrl = "http://myServer/UserImages/";
FileInfo fi = //load with the file path C:\UserImages\1234.jpg;
img_myImageControl.ImageURL = baseImgUrl + fi.FileName;
haven't tested this, but it should get you on the right track.
You could just do something like this to show the image in the GridView:
<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<img src='<%# DataBinder.Eval(Container.DataItem,"ImageAddress") %>' alt='I am a user image' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Of course you'd have to modify things a bit (depending on how you have things saved in the database).
精彩评论