Click here to Skip to main content
15,891,864 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Am working in asp.net.. Here am going to display images in datalist.. But the datalist doesn't show the image..

XML
<asp:DataList ID="list" runat="server" OnItemCommand="list_ItemCommand" RepeatColumns="7"
                       ShowFooter="true" ShowHeader="true"  Width="98%">
                   <ItemTemplate>
                       <div align="center">
                           <asp:Image ID="img" runat="server" BorderColor="white" BorderWidth="2" Height="100"
                               ImageUrl='<%# 
 +Eval("image") %>' Width="100px" />
                         <asp:HiddenField ID="hf1" runat="server" Value='<%# Eval("id") %>' />
                           <br />
                           <span onclick="return confirm('Are you sure to Remove this Image?')">
                               <asp:LinkButton ID="linkremove" runat="server" CommandName="Removes" Text="Remove"></asp:LinkButton>
                           </span>
                       </div>
                   </ItemTemplate>

                   </asp:DataList>

Also i need how to delete the particular image in datalist??
Can any one help me?? Thanks in advance :)


Now the image displayed properly... But the datalist Item command delete operation not firing..

C#
protected void list_ItemCommand(object source, DataListCommandEventArgs e)
    {
        try
        {
            if (e.CommandName == "Removes")
            {
                HiddenField id1 = (HiddenField)list.Items[e.Item.ItemIndex].FindControl("hf1");
                if (dbo.deleterecords("image", "id='" + id1.Value + "'") == true)
                {

                   BindItemsList();
                    lbldel.Text = "Image Deleted";
                }
            }
        }
        catch (Exception ex)
        {
            Exception E = ex;
        }
    }
Posted
Updated 7-Jan-13 23:59pm
v2
Comments
_Amy 8-Jan-13 4:50am    
Where is your image? Is it in any folder or coming from database?
Sasikala Gurusamy 8-Jan-13 4:52am    
Its from database..
_Amy 8-Jan-13 4:54am    
Check my answers. You need to use handler to display the images from database.
Sanjay K. Gupta 8-Jan-13 5:04am    
The database stored image path or image(in byte) itself
Sasikala Gurusamy 8-Jan-13 5:05am    
It stored in bytes only

You need to use handler to display the images from database. Here is the list of articles which will explain your need:
Image Handling In ASP.NET[^]
Save and Retrieve Images from the Database using ASP.NET[^]


--Amit
 
Share this answer
 
Add a label to your datalist and set its text to '<%# Eval("image") %>' and check if it is displaying the correct path? To delete the image use datalist's itemcommand event.
 
Share this answer
 
Comments
Sasikala Gurusamy 8-Jan-13 4:53am    
If i add label means how it shows the image??
Sanjay K. Gupta 8-Jan-13 5:02am    
Check only image path, not the image

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