Exemplo n.º 1
0
        protected override int CreateChildControls(System.Collections.IEnumerable dataSource, bool dataBinding)
        {
            if (this.DesignMode)
            {
                return(0);
            }
            ICollection items = dataSource as ICollection;

            if (items != null && items.Count > 0)
            {
                IEnumerator ienum = items.GetEnumerator();
                ienum.Reset();
                ienum.MoveNext();
                object       firstObject   = ienum.Current;
                Type         itemType      = firstObject.GetType();
                PropertyInfo piTitle       = (!string.IsNullOrEmpty(PropertyTitle) ? itemType.GetProperty(PropertyTitle) : null);
                PropertyInfo piDescription = (!string.IsNullOrEmpty(PropertyDescription) ? itemType.GetProperty(PropertyDescription) : null);
                PropertyInfo piImageUrl    = (!string.IsNullOrEmpty(PropertyImageUrl) ? itemType.GetProperty(PropertyImageUrl) : null);
                PropertyInfo piNavigateUrl = (!string.IsNullOrEmpty(PropertyNavigateUrl) ? itemType.GetProperty(PropertyNavigateUrl) : null);
                foreach (object obj in items)
                {
                    SlideShowItem sItem = new SlideShowItem();
                    object        value = null;
                    if (piTitle != null)
                    {
                        value       = piTitle.GetValue(obj, null);
                        sItem.Title = (value != null ? value.ToString() : "");
                    }
                    if (piDescription != null)
                    {
                        value             = piDescription.GetValue(obj, null);
                        sItem.Description = (value != null ? value.ToString() : "");
                    }
                    if (piImageUrl != null)
                    {
                        value          = piImageUrl.GetValue(obj, null);
                        sItem.ImageUrl = (value != null ? value.ToString() : "");
                    }
                    if (piNavigateUrl != null)
                    {
                        value             = piNavigateUrl.GetValue(obj, null);
                        sItem.NavigateUrl = (value != null ? value.ToString() : "");
                    }
                    this.Items.Add(sItem);
                }
            }
            return(0);
        }
Exemplo n.º 2
0
        protected override void Render(HtmlTextWriter writer)
        {
            CompositeDataBoundControl slideDiv   = this;
            HtmlGenericControl        pictureDiv = new HtmlGenericControl("div");

            pictureDiv.ID = "pic";
            HyperLink slideHyperlink = new HyperLink();

            slideHyperlink.ID = "linkSlide";
            Image slideImage = new Image();

            slideImage.ID = "slideImage";
            HtmlGenericControl titleSlideDiv = new HtmlGenericControl("div");

            titleSlideDiv.ID = "titleSlide";
            slideHyperlink.Controls.Add(slideImage);
            slideHyperlink.Controls.Add(titleSlideDiv);
            pictureDiv.Controls.Add(slideHyperlink);
            HtmlGenericControl textSlideDiv = new HtmlGenericControl("div");

            textSlideDiv.ID = "textSlide";
            pictureDiv.Controls.Add(textSlideDiv);
            HtmlGenericControl navDiv = new HtmlGenericControl("div");

            navDiv.ID = "nav";
            if (Items.Count > 0)
            {
                HtmlGenericControl pageUl = new HtmlGenericControl("ul");
                if (this.PagerSettings.Mode == PagerButtons.NextPrevious || this.PagerSettings.Mode == PagerButtons.NextPreviousFirstLast)
                {
                    HtmlGenericControl previousLi        = new HtmlGenericControl("li");
                    HyperLink          previousHyperlink = new HyperLink();
                    previousHyperlink.NavigateUrl = "#";
                    previousHyperlink.Attributes.Add("onclick", this.ClientID + ".previous()");
                    previousHyperlink.Text = PagerSettings.PreviousPageText;
                    previousLi.Controls.Add(previousHyperlink);
                    pageUl.Controls.Add(previousLi);
                }
                for (int i = 1; i <= Items.Count; i++)
                {
                    HtmlGenericControl itemLi        = new HtmlGenericControl("li");
                    HyperLink          itemHyperlink = new HyperLink();
                    itemHyperlink.NavigateUrl = "#";
                    itemHyperlink.Attributes.Add("onclick", this.ClientID + ".position(" + (i - 1) + ")");
                    itemHyperlink.Text = i.ToString();
                    itemLi.Controls.Add(itemHyperlink);
                    pageUl.Controls.Add(itemLi);
                }
                if (this.PagerSettings.Mode == PagerButtons.NextPrevious || this.PagerSettings.Mode == PagerButtons.NextPreviousFirstLast)
                {
                    HtmlGenericControl nextLi        = new HtmlGenericControl("li");
                    HyperLink          nextHyperlink = new HyperLink();
                    nextHyperlink.NavigateUrl = "#";
                    nextHyperlink.Attributes.Add("onclick", this.ClientID + ".next()");
                    nextHyperlink.Text = PagerSettings.NextPageText;
                    nextLi.Controls.Add(nextHyperlink);
                    pageUl.Controls.Add(nextLi);
                }
                navDiv.Controls.Add(pageUl);
            }
            slideDiv.Controls.Add(pictureDiv);
            slideDiv.Controls.Add(navDiv);
            if (!this.DesignMode)
            {
                HtmlGenericControl itemsDiv = new HtmlGenericControl("div");
                itemsDiv.ID = "items";
                for (int i = 0; i < Items.Count; i++)
                {
                    SlideShowItem      item    = Items[i];
                    HtmlGenericControl itemDiv = new HtmlGenericControl("div");
                    itemDiv.ID = "item" + i;
                    itemDiv.Attributes.Add("image", item.ImageUrl);
                    itemDiv.Attributes.Add("href", (string.IsNullOrEmpty(item.NavigateUrl) ? "#" : Page.ResolveUrl(item.NavigateUrl)));
                    itemDiv.Attributes.Add("title", item.Title);
                    itemDiv.InnerText = item.Description;
                    itemsDiv.Controls.Add(itemDiv);
                }
                slideDiv.Controls.Add(itemsDiv);
            }
            this.RenderBeginTag(writer);
            this.RenderChildren(writer);
            this.RenderEndTag(writer);
        }