开发者

showing images through gridview?

suppose my images binary data is saved in database table and i want to show those images through gridview. one approach is just create one page where i will pass some id as query string and that page will retrieve the image data from db and stream down the image data to my page through BinaryWrite method. a example is http://www.aspdotnetcodes.com/Insert_Images_Database.aspx. this url describe how to show image data through BinaryWrite. this approach is old and i know. is there any other way by which i can show the image in gridview but i don't want to store image url in table.please let me know if you know any other approach for showing the images through gridiview when image binary d开发者_运维问答ata is stored in db. thanks


I asked a similar question here:

Streaming Databased Images Using HttpHandler

Note that I had to use a DataReader in my final version :-)


It sounds like you've got your images stored in your database in binary format. You then want to show them in your GridView.

Consider this approach:

  • create a template field in your gridview to hold your image. It'll end up calling a handler URL to grab the binary data for your image.
  • create the image handler page -- make it an .ashx. Put a unique identifier on the querystring, for example, to grab the image you want from the database
<Columns>
    <asp:TemplateField HeaderText="Image">
     <ItemTemplate>
        <asp:Image ID="Image1" runat="server"  Height="80px" Width="80px" 
        ImageUrl='<%# "ImageHandler.ashx?ImID="+ Eval("ImageID")
                   %>'/>
     </ItemTemplate>
</asp:TemplateField>
</Columns>

See the answer at the bottom of this MSDN question for more details on how to implement your image handler. You then won't have to bring back the binary data when binding your GridView. On the other hand, it creates n calls to the handler for each row in the grid.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜