Click here to Skip to main content
13,703,250 members
Rate this:
 
Please Sign up or sign in to vote.
Hi all,
I need to load an image to image tag .The image name is stored in a table in database.
The image is located in a subfolder in the project folder.What I need is that , there is a gridview and when the corresponding button against the gridview row is clicked, the image should be loaded into the image tag .
How can I do this.Any help will be really appreciated.

What I have tried:

<tr>
                                                                <td colspan="2" align="right">
                                                                    <asp:UpdatePanel ID="UpdatePanel7" UpdateMode="Conditional" runat="server">
                                                                        <ContentTemplate>
                                                                             <asp:DataList ID="DataList1" Width="100%"  DataSourceID="SqlDataSource1" DataKeyField="IN005_01" runat="server">
                                                                                 <ItemTemplate>
                                                                                     <table>
                                                                                         <tr>
                                                                                             <td>

                                                                                             
                                                                    <asp:Image ID="Image1" Width="100px" Height="100px" ImageUrl='<%# Bind("mgname", "~/UserCertificates/{0}") %>'  runat="server" />
                                                                                                 </td>
                                                                                         </tr>
                                                                                     </table>
                                                                          </ItemTemplate>
                                                                                 </asp:DataList>
                                                                          <asp:SqlDataSource ID="SqlDataSource1" runat="server" 

                                                                        ConnectionString="<%$ ConnectionStrings:INSMCPConnectionString %>" 

                                                                        SelectCommand="select imgname FROM img  INNER JOIN imgpr ON imgpr.IN005_01=img.IN005_01 where img.IN005_01=@IN005_01 and IN005_01_07='photo'">

                                                                        <SelectParameters>
                                                                            

                                                                            <asp:ControlParameter ControlID="grd_UserEdit" Name="IN005_01" 

                                                                                PropertyName="SelectedValue" />
                                                                            

                                                                        </SelectParameters>
                                                                        

                                                                    </asp:SqlDataSource>
                                                                        </ContentTemplate>
                                                                        <Triggers>
    
<asp:AsyncPostBackTrigger ControlID="but_search" />
    
<asp:AsyncPostBackTrigger ControlID="grd_UserEdit" />
    
</Triggers>
                                                                         </asp:UpdatePanel>
                                                                    
                                                                  
                                                                        </td>
                                                            </tr>
Posted 2-Jan-18 0:39am
Updated 2-Jan-18 20:28pm
v2

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Hi,

This has been asked many times before in various forums. I would highly recommend you to do a quick search in the web to get more examples.

Here are some articles that I've blogged about before regarding saving, validating and displaying images in the context of ASP.NET that might be useful for your case: ASP.NET WebForms: Uploading, Validating And Displaying of Image[^]
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web01-2016 | 2.8.180920.1 | Last Updated 3 Jan 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100