Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Updated 2-Jan-18 20:28pm
v2

1 solution

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[^]
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900