Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

Populating Array From database

$
0
0

Hi guys.

I'm working with an AjaxControlToolKit SlideShowExtender and I want to show the images from my database. I am also using Entity Framework. My code for this is as follows

//Web Service MEthod To Load Images for Property
        [System.Web.Services.WebMethod]
        [System.Web.Script.Services.ScriptMethod]

        public static AjaxControlToolkit.Slide[] GetImages()
        {
            //get property ID from Query String
            int propID = Convert.ToInt32(HttpContext.Current.Request.QueryString["prop_id"]);

            //List to hold all the images
           List<AjaxControlToolkit.Slide> propertyImages = new List<Slide>();
            //get all images for this property
            //get the default image
            using (var context = new VillaMedulaEntities())
            {

                var property = from p in context.Properties
                               where p.Property_id == propID
                               select p;
                //only one row
                if (property.Count() == 1)
                {
                    //define main image slide object
                    Slide defaultImg = new Slide(property.FirstOrDefault().Image, "Main Image", "This is the main image for this property");
                    //Add to List
                    propertyImages.Add(defaultImg);
                }
            }
            //get all other images
            using (var context = new VillaMedulaEntities())
            {
                //get all the images for this property
                var propImages = from i in context.PropertyImages
                                 where i.Property_id == propID
                                 select i;
                //add Image paths
                for (int i = 0; i < propImages.Count(); i++)
                {
                    //define Images with Title and Description
                    Slide newImg = new Slide(propImages.ElementAt(i).Image_path, propImages.ElementAt(i).Title, propImages.ElementAt(i).Description);
                    //add to List
                    propertyImages.Add(newImg);
                }
            }
           return propertyImages.ToArray();
        }
    }

I just dont seem to know what is wrong.


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>