Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
In my project i want to save an image in my project ,inside an images folder,then store the url of that image in database.After that i want to retrieve that image in a repeater control .Please help me to do that.

Thanks in advance
Posted
Comments
Chinmaya C 29-Apr-13 3:09am    
Have you tried with the following statement for ItemTemplate of Repeater control:

<asp:Image ID="Image1" ImageUrl='<%#Container.DataItem("Column_Name")%>' runat="server" />

Replace Column_Name with your database column name which contains the url to image.
Himani Tyagi 29-Apr-13 3:17am    
yes i've tried this but this isnt working...
Chinmaya C 29-Apr-13 3:19am    
Could you please post your code, so that it will be easier for us to understand.

1 solution

for dispalying image in repeater control try:
XML
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>"
            SelectCommand="SELECT * FROM [country]"></asp:SqlDataSource>
        <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1" OnItemDataBound="Repeater1_ItemDataBound">
         <ItemTemplate>
             <asp:HiddenField Value='<%# Eval("id") %>' ID="HiddenField1" runat="server" />
             <asp:Image ID="Image1" runat="server" />
         </ItemTemplate>
        </asp:Repeater>

and in aspx.cs
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        HiddenField hf =  e.Item.FindControl("HiddenField1") as HiddenField;
        if (hf != null)
        {
            string val = hf.Value;
            Image img = e.Item.FindControl("Image1") as Image;
            img.ImageUrl = "~/image" + val + ".jpg";
        }
       
 

    }


You also can refer Repeater control with image in asp.net[^]
 
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