Click here to Skip to main content
15,892,222 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello sir,

I am saving one image to images folder in my solution.
I have three columns, eid, ename and image in my table, and I am saving eid, ename, imagepath in these columns.

I want to retrive this information in gridview next page.

How can I bind this image from folder to gridview using imagepath in database?

Anybody please help me.
Thank you.
Posted
Updated 27-Dec-10 20:13pm
v2
Comments
Dalek Dave 28-Dec-10 2:13am    
Edited for Grammar and Readability.

I dont understand the problem, that you are facing. You must be having some image control in your grdiview.Get the image path from database and set the src of that imagecontrol.
Is there any other issue?
 
Share this answer
 
Comments
Dalek Dave 28-Dec-10 2:13am    
Good Answer.
Try the followings:

1. Add an Image field to the GridView and convert the field to Template field

XML
<asp:GridView ID="GridView1" runat="server"
            onrowdatabound="GridView1_RowDataBound">
            <Columns>
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:Image ID="Image1" runat="server" />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
</asp:GridView>


2. Inside the RowDataBound() event method, find the Image control and assign the ImageUrl property as follows:

C#
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
       if (e.Row.RowType == DataControlRowType.DataRow)
       {
           int Id = Convert.ToInt32(e.Row.DataItem);
           Image img = e.Row.FindControl("Image1") as Image;
           img.ImageUrl = GetImageUrl(Id);
       }
}


Build an appropriate Image Url inside the GetImageUrl(Id) method using the Image Id. From the Database you know the actual physical location of the image and if the image is stored within the web application folder, you just need to calculate the relative path of the images based upon their physical path within the folder.

Hope this helps.
 
Share this answer
 
Comments
Dalek Dave 28-Dec-10 2:14am    
Good answer, very helpful.
Member 7762031 13-Apr-11 7:29am    
How to Build an appropriate Image Url inside the GetImageUrl(Id) method using the Image Id. From the Database you know the actual physical location of the image and if the image is stored within the web application folder, you just need to calculate the relative path of the images based upon their physical path within the folder????????

Member 7762031 13-Apr-11 7:33am    
I m saving Image name & ImagePath into one table called Product, which also includes ProductId Pk, ProductName, Description. I want this info along with Image into GridView. I m saving Image into one folder in "C:\ProjectProduct\ImageStorage\"

Please Help me ....

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