コード例 #1
0
ファイル: DataPager.cs プロジェクト: adamjez/dotvvm
 private void SetButtonContent(RedwoodRequestContext context, LinkButton button, string text, ITemplate contentTemplate)
 {
     if (contentTemplate != null)
     {
         contentTemplate.BuildContent(context, button);
     }
     else
     {
         button.Text = text;
     }
 }
コード例 #2
0
ファイル: DataPager.cs プロジェクト: adamjez/dotvvm
        protected override void RenderContents(IHtmlWriter writer, RenderContext context)
        {
            writer.AddKnockoutDataBind("css", "{ 'disabled': IsFirstPage() }");
            firstLi.Render(writer, context);

            writer.AddKnockoutDataBind("css", "{ 'disabled': IsFirstPage() }");
            previousLi.Render(writer, context);

            // render template
            writer.WriteKnockoutDataBindComment("foreach", "NearPageIndexes");
            context.PathFragments.Push("NearPageIndexes[$index]");

            // render page number
            numbersPlaceholder.Children.Clear();
            HtmlGenericControl li;
            if (!RenderLinkForCurrentPage)
            {
                writer.AddKnockoutDataBind("visible", "$data == $parent.PageIndex()");
                li = new HtmlGenericControl("li");
                li.SetValue(Internal.IsDataContextBoundaryProperty, true);
                var literal = new Literal();
                literal.SetBinding(Literal.TextProperty, new ValueBindingExpression("_this + 1"));
                li.Children.Add(literal);
                numbersPlaceholder.Children.Add(li);
                li.Render(writer, context);

                writer.AddKnockoutDataBind("visible", "$data != $parent.PageIndex()");
            }
            writer.AddKnockoutDataBind("css", "{ 'active': $data == $parent.PageIndex()}");
            li = new HtmlGenericControl("li");
            li.SetValue(Internal.IsDataContextBoundaryProperty, true);
            var link = new LinkButton();
            link.SetBinding(ButtonBase.TextProperty, new ValueBindingExpression("_this + 1"));
            link.SetBinding(ButtonBase.ClickProperty, new CommandBindingExpression("_parent.GoToPage(_this)"));
            li.Children.Add(link);
            numbersPlaceholder.Children.Add(li);
            li.Render(writer, context);

            context.PathFragments.Pop();
            writer.WriteKnockoutDataBindEndComment();

            writer.AddKnockoutDataBind("css", "{ 'disabled': IsLastPage() }");
            nextLi.Render(writer, context);

            writer.AddKnockoutDataBind("css", "{ 'disabled': IsLastPage() }");
            lastLi.Render(writer, context);
        }
コード例 #3
0
ファイル: DataPager.cs プロジェクト: adamjez/dotvvm
        private void DataBind(RedwoodRequestContext context)
        {
            Children.Clear();

            content = new HtmlGenericControl("ul");
            content.SetBinding(DataContextProperty, GetDataSetBinding().Clone());
            Children.Add(content);

            var dataSet = DataSet;
            if (dataSet != null)
            {
                // first button
                firstLi = new HtmlGenericControl("li");
                var firstLink = new LinkButton();
                SetButtonContent(context, firstLink, "««", FirstPageTemplate);
                firstLink.SetBinding(ButtonBase.ClickProperty, new CommandBindingExpression("GoToFirstPage()"));
                firstLi.Children.Add(firstLink);
                content.Children.Add(firstLi);

                // previous button
                previousLi = new HtmlGenericControl("li");
                var previousLink = new LinkButton();
                SetButtonContent(context, previousLink, "«", PreviousPageTemplate);
                previousLink.SetBinding(ButtonBase.ClickProperty, new CommandBindingExpression("GoToPreviousPage()"));
                previousLi.Children.Add(previousLink);
                content.Children.Add(previousLi);

                // number fields
                numbersPlaceholder = new Placeholder();
                content.Children.Add(numbersPlaceholder);

                var i = 0;
                foreach (var number in dataSet.NearPageIndexes)
                {
                    var li = new HtmlGenericControl("li");
                    li.SetBinding(DataContextProperty, new ValueBindingExpression("NearPageIndexes[" + i + "]"));
                    if (number == dataSet.PageIndex)
                    {
                        li.Attributes["class"] = "active";
                    }
                    var link = new LinkButton() { Text = (number + 1).ToString() };
                    link.SetBinding(ButtonBase.ClickProperty, new CommandBindingExpression("_parent.GoToPage(_this)"));
                    li.Children.Add(link);
                    numbersPlaceholder.Children.Add(li);

                    i++;
                }

                // next button
                nextLi = new HtmlGenericControl("li");
                var nextLink = new LinkButton();
                SetButtonContent(context, nextLink, "»", NextPageTemplate);
                nextLink.SetBinding(ButtonBase.ClickProperty, new CommandBindingExpression("GoToNextPage()"));
                nextLi.Children.Add(nextLink);
                content.Children.Add(nextLi);

                // last button
                lastLi = new HtmlGenericControl("li");
                var lastLink = new LinkButton();
                SetButtonContent(context, lastLink, "»»", LastPageTemplate);
                lastLink.SetBinding(ButtonBase.ClickProperty, new CommandBindingExpression("GoToLastPage()"));
                lastLi.Children.Add(lastLink);
                content.Children.Add(lastLi);
            }
        }
コード例 #4
0
ファイル: GridViewColumn.cs プロジェクト: adamjez/dotvvm
        public virtual void CreateHeaderControls(RedwoodRequestContext context, GridView gridView, string sortCommandPath, HtmlGenericControl cell)
        {
            if (AllowSorting)
            {
                if (string.IsNullOrEmpty(sortCommandPath))
                {
                    throw new Exception("Cannot use column sorting where no sort command is specified. Either put IGridViewDataSet in the DataSource property of the GridView, or set the SortChanged command on the GridView to implement custom sorting logic!");
                }

                var sortExpression = GetSortExpression();

                // TODO: verify that sortExpression is a single property name

                var linkButton = new LinkButton() { Text = HeaderText };
                linkButton.SetBinding(ButtonBase.ClickProperty, new CommandBindingExpression(string.Format("{0} (\"{1}\")", sortCommandPath, sortExpression)));
                cell.Children.Add(linkButton);
            }
            else
            {
                var literal = new Literal(HeaderText);
                cell.Children.Add(literal);
            }
        }