Click here to Skip to main content
15,905,325 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have used a repeater control to view all images from a folder. but images are not getting displayed. can u help me please.

This is my code..
C#
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
   {
       XmlDocument xmldoc = new XmlDocument();
       xmldoc.Load(Server.MapPath("~/" + "XML/album.xml"));
       XmlNodeList nodelist = xmldoc.GetElementsByTagName("Album");
       DataTable dt = (DataTable)Session["dt"];
       if (dt.Rows.Count > 0)
       {
           for (int i = 0; i < nodelist.Count; i++)
           {
               string val = e.CommandArgument.ToString();

               string attr = nodelist[i].Attributes["Name"].Value;
               if (attr == val)
               {
                   List<string> images = new List<string>();
                   DirectoryInfo di = new DirectoryInfo(Server.MapPath("") + "\\" + val + "\\" + "Images\\");
                   int count = di.GetFiles().Length;
                   //all Images in folder add in datarow and bind to repeater control
                   DataTable imgdt = new DataTable();
                   for (int j = 0; j < count; j++)
                   {
                      string imgpath=nodelist[i].InnerText;

                       DirectoryInfo directoryInfo = new DirectoryInfo(imgpath);
                       FileInfo[] fileInfo = directoryInfo.GetFiles();

                       images.Add(fileInfo[j].Name);
                   }

                   Repeater2.DataSource = images; // i am getting image name here
                   Repeater2.DataBind();
               }
           }
       }
   }

this the desgin view.
XML
<asp:Repeater ID="Repeater2" runat="server" onitemcommand="Repeater1_ItemCommand">
                        <ItemTemplate>
                            <td>
                                <asp:Image ID="Image1" runat="server" ImageUrl="<%# Container.DataItem %>"/>
                            </td>
                        </ItemTemplate>
                    </asp:Repeater>
Posted
Updated 6-Feb-14 20:05pm
v3

Hi,

What do you see when the repeater is rendered? What path is being rendered in the HTML for each row? Is that path correct for an image? I am guessing it isn't. Please let me know.
 
Share this answer
 
Comments
sumit kausalye 3-Feb-14 3:35am    
I am getting path and images from the folder but yet it is not getting display

DataTable imgdt = new DataTable();
for (int j = 0; j < count; j++)
{
string imgpath=nodelist[i].InnerText; // here i am getting path of the folder

DirectoryInfo directoryInfo = new DirectoryInfo(imgpath);
FileInfo[] fileInfo = directoryInfo.GetFiles();

images.Add(fileInfo[j].Name); // here i am getting images in that folder.

}

Repeater2.DataSource = images; // i am getting image name here
Repeater2.DataBind();
}
CoderPanda 3-Feb-14 3:38am    
This is all right. I am more interested in the HTML that is rendered. Can you please do a
'view->source' on the browser where the repeater is displayed and paste the HTML portion for the repeater only?
sumit kausalye 3-Feb-14 3:52am    
Sir i just see a blank repeater control. no images are added in that repeater control.
sumit kausalye 3-Feb-14 3:55am    
Sir i guess i have make changes in image tag in design view. but what should i add to bind dynamic path to image control.
CoderPanda 3-Feb-14 4:10am    
You shouldn't have to make anything in the design view. I still want to see the HTML that is rendered when you run the app. So far you have only given me the server side code.

When you run the app, go to the browser and get the HTML for the empty repeater. It should be a HTML table.
C#
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        XmlDocument xmldoc = new XmlDocument();
        xmldoc.Load(Server.MapPath("~/" + "XML/album.xml"));
        XmlNodeList nodelist = xmldoc.GetElementsByTagName("Album");
        DataTable dt = (DataTable)Session["dt"];
        if (dt.Rows.Count > 0)
        {
            for (int i = 0; i < nodelist.Count; i++)
            {
                string val = e.CommandArgument.ToString();
                string attr = nodelist[i].Attributes["Name"].Value;
                if (attr == val)
                {
                    List<string> images = new List<string>();
                    DirectoryInfo di = new DirectoryInfo(Server.MapPath("") + "\\Gallary\\" + val + "\\" + "Images\\");
                    int count = di.GetFiles().Length;
                    //all Images in folder add in datarow and bind to repeater control
                    DataTable imgdt = new DataTable();
                    imgdt.Columns.Add("ImagesFolder", typeof(string));
                    for (int j = 0; j < count; j++)
                    {

                        DataRow dr = imgdt.NewRow();
                        string imgpath = nodelist[i].InnerText;
                        //bind folder images to datarow here.
                        dr["ImagesFolder"] = nodelist[i].InnerText;
                        imgdt.Rows.Add(dr);
                        DirectoryInfo directoryInfo = new DirectoryInfo(imgpath);
                        FileInfo[] fileInfo = directoryInfo.GetFiles();
                        string fullpath = "~\\Gallary\\" + val + "\\" + "Images\\" + fileInfo[j].Name;
                        images.Add(fullpath);                       
                    }
                     Repeater2.DataSource = images;
                     Repeater2.DataBind();
                }
            }
        }
    }</string></string>
 
Share this answer
 
v2

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