Пример #1
0
        public virtual void CreateHeaderControls(IDotvvmRequestContext context, GridView gridView, Action <string> sortCommand, HtmlGenericControl cell, IGridViewDataSet gridViewDataSet)
        {
            if (HeaderTemplate != null)
            {
                HeaderTemplate.BuildContent(context, cell);
                return;
            }

            if (AllowSorting)
            {
                if (sortCommand == null)
                {
                    throw new DotvvmControlException(this, "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();

                var linkButton = new LinkButton();
                linkButton.SetValue(LinkButton.TextProperty, GetValueRaw(HeaderTextProperty));
                cell.Children.Add(linkButton);

                var bindingId = linkButton.GetValue(Internal.UniqueIDProperty) + "_sortBinding";
                var binding   = new CommandBindingExpression(context.Services.GetRequiredService <BindingCompilationService>().WithoutInitialization(), h => sortCommand(sortExpression), bindingId);
                linkButton.SetBinding(ButtonBase.ClickProperty, binding);

                SetSortedCssClass(cell, gridViewDataSet);
            }
            else
            {
                var literal = new Literal();
                literal.SetValue(Literal.TextProperty, GetValueRaw(HeaderTextProperty));
                cell.Children.Add(literal);
            }
        }
Пример #2
0
        public virtual void CreateHeaderControls(IDotvvmRequestContext context, GridView gridView, Action <string> sortCommand, HtmlGenericControl cell)
        {
            if (AllowSorting)
            {
                if (sortCommand == null)
                {
                    throw new DotvvmControlException(this, "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();

                var linkButton = new LinkButton();
                if (HeaderTemplate != null)
                {
                    HeaderTemplate.BuildContent(context, linkButton);
                }
                else
                {
                    linkButton.Text = HeaderText;
                }
                cell.Children.Add(linkButton);
                var bindingId = linkButton.GetValue(Internal.UniqueIDProperty) + "_sortBinding";
                var binding   = new CommandBindingExpression(h => sortCommand(sortExpression), bindingId);
                linkButton.SetBinding(ButtonBase.ClickProperty, binding);
            }
            else
            {
                if (HeaderTemplate == null)
                {
                    var literal = new Literal(HeaderText);
                    cell.Children.Add(literal);
                }
                else
                {
                    HeaderTemplate.BuildContent(context, cell);
                }
            }
        }
Пример #3
0
        public virtual void CreateHeaderControls(IDotvvmRequestContext context, GridView gridView, Action<string> sortCommand, HtmlGenericControl cell, IGridViewDataSet gridViewDataSet)
        {
            if (HeaderTemplate != null)
            {
                HeaderTemplate.BuildContent(context, cell);
                return;
            }

            if (AllowSorting)
            {
                if (sortCommand == null)
                {
                    throw new DotvvmControlException(this, "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();

                var linkButton = new LinkButton();
                linkButton.SetValue(LinkButton.TextProperty, GetValueRaw(HeaderTextProperty));
                cell.Children.Add(linkButton);

                var bindingId = linkButton.GetValue(Internal.UniqueIDProperty) + "_sortBinding";
                var binding = new CommandBindingExpression(h => sortCommand(sortExpression), bindingId);
                linkButton.SetBinding(ButtonBase.ClickProperty, binding);

                SetSortedCssClass(cell, gridViewDataSet);
            }
            else
            {
                var literal = new Literal();
				literal.SetValue(Literal.TextProperty, GetValueRaw(HeaderTextProperty));
                cell.Children.Add(literal);
            }
        }
Пример #4
0
        public virtual void CreateHeaderControls(DotvvmRequestContext context, GridView gridView, Action<string> sortCommand, HtmlGenericControl cell)
        {
            if (AllowSorting)
            {
                if (sortCommand == null)
                {
                    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();

                var linkButton = new LinkButton() { Text = HeaderText };
                cell.Children.Add(linkButton);
                var bindingId = linkButton.GetValue(Internal.UniqueIDProperty) + "_sortBinding";
                var binding = new CommandBindingExpression((o, i) => { sortCommand(sortExpression); return null; }, bindingId);
                linkButton.SetBinding(ButtonBase.ClickProperty, binding);
            }
            else
            {
                var literal = new Literal(HeaderText);
                cell.Children.Add(literal);
            }
        }