This is a migrated thread and some comments may be shown as answers.

Sort GridButtonColumn C#

7 Answers 187 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Billy
Top achievements
Rank 1
Billy asked on 11 Apr 2011, 08:33 PM
I need to sort a GridButtonColumn in a C# asp.net project.

I've added the c# class listed in this thread

 http://www.telerik.com/community/code-library/aspnet-ajax/grid/filtering-and-sorting-for-gridbuttoncolumn.aspx

and I can't get it to work.  I get this "The type or namespace name 'GridButtonColumn' could not be found"

Is there using directive that I need to add?


The VB example uses "Imports Telerik.WebControls".  When I add using Telerik.WebControls;  I get this message

"The type or namespace name 'WebControls' does not exist in the namespace 'Telerik' (are you missing an assembly reference?)"

7 Answers, 1 is accepted

Sort by
0
Vasil
Telerik team
answered on 12 Apr 2011, 03:19 PM
Hi Billy,

You should use:
Imports Telerik.Web.UI

In the code library two archives are available. One for the classic controls and one for the newer Ajax controls.
You should use GridButtonColumnWithFilteringSorting-AJAX.zip
I just tested it and it is working fine. You just need to copy Telerik.Web.UI.dll from the installation folder of the RadControls to the \bin folder of the website after extracting it from the zip file.

All the best,
Vasil
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Billy
Top achievements
Rank 1
answered on 14 Apr 2011, 03:57 PM
I get this when I try to run the ajax example website

Server Error in '/Ajax' Application.

Configuration Error

Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: Could not load file or assembly 'System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

Source Error:

Line 30: 		<compilation debug="true">
Line 31: 			<assemblies>
Line 32: 				<add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
Line 33: 				<add assembly="System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
Line 34: 				<add assembly="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
0
Billy
Top achievements
Rank 1
answered on 14 Apr 2011, 04:31 PM

I’m getting this error message in my project

“Unknown server tag 'telerik:GridButtonColumnWithFilteringSorting'.”

I have added this tag to the page


<%@ Register TagPrefix="custom" Namespace="GridButtonColumnWithFilteringSortingNS" %>

 

For this column I changed the “GridButton” to “GridButtonColumnWithFilteringSorting

<telerik:GridButtonColumnWithFilteringSorting ButtonType="LinkButton" UniqueName="Description" SortExpression="Description"

                ShowSortIcon="true" HeaderText="Task Description" ItemStyle-HorizontalAlign="Left"

                DataTextField="TaskLookupDtls.Description">

</telerik:GridButtonColumnWithFilteringSorting>


And I added this class GridButtonColumnWithFiltering.cs

 

using Telerik.Web.UI;

using System.Web.UI.WebControls;

 

namespace GridButtonColumnWithFilteringSortingNS

{

    public class GridButtonColumnWithFilteringSorting : GridButtonColumn

    {

 

        public string DataField

        {

            get

            {

                object MyRes = this.ViewState["_df"];

                if (MyRes != null)

                {

                    return (string)MyRes;

                }

                return string.Empty;

            }

            set { this.ViewState["_df"] = value; }

        }

        public override string SortExpression

        {

            get

            {

                object MyRes = this.ViewState["_se"];

                if (MyRes != null)

                {

                    return (string)MyRes;

                }

                return string.Empty;

            }

            set { this.ViewState["_se"] = value; }

        }

 

        protected override void SetupFilterControls(TableCell cell)

        {

            base.SetupFilterControls(cell);

            cell.Controls.RemoveAt(0);

            cell.Controls.AddAt(0, new TextBox());

        }

 

        public override GridColumn Clone()

        {

            return base.Clone();

        }

 

        protected override string GetFilterDataField()

        {

            return this.DataField;

        }

 

        protected override void SetCurrentFilterValueToControl(TableCell cell)

        {

            base.SetCurrentFilterValueToControl(cell);

 

            if (!object.ReferenceEquals(this.CurrentFilterValue, string.Empty))

            {

                ((TextBox)cell.Controls[0]).Text = this.CurrentFilterValue;

            }

        }

 

        protected override string GetCurrentFilterValueFromControl(TableCell cell)

        {

            return ((TextBox)cell.Controls[0]).Text;

        }

 

        public override bool SupportsFiltering()

        {

            return true;

        }

    }

}

0
Vasil
Telerik team
answered on 15 Apr 2011, 03:36 PM
Hi Billy,

I am attaching a working version in C# of the example. Please check it out.

Kind regards,
Vasil
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Billy
Top achievements
Rank 1
answered on 18 Apr 2011, 05:28 PM

I've added the class file and the register statements and It still won't sort.  Is there something I need to change on the column.  Here's what I have.

            <custom:GridButtonColumnWithFilteringSorting
                ButtonType="LinkButton"
                UniqueName="Description"
                SortExpression="Description"
                ShowSortIcon="true"
                HeaderText="Task Description"
                ItemStyle-HorizontalAlign="Left"
                DataTextField="TaskLookupDtls.Description">
            </custom:GridButtonColumnWithFilteringSorting>
0
Vasil
Telerik team
answered on 19 Apr 2011, 09:18 AM
Hello Billy,

The column's declaration looks correct.

If the column is appearing now but you can click to sort it, then make sure to set AllowSorting="true" in the RadGrid's declaration.

If you still get "Unknown server tag" error then make sure that GridButtonColumnWithFiltering.cs is in the app_code folder of your project.

All the best,
Vasil
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Robert
Top achievements
Rank 1
answered on 23 May 2013, 09:36 AM
If you develop a web application project there is no app_code folder. In this case you can just put the GridButtonColumnWithFiltering.cs file anywhere you want and register it like this:

<%@ Register Assembly="AssemblyName" TagPrefix="custom" Namespace="GridButtonColumnWithFilteringSortingNS" %>

Cheers,
Robert
Tags
Grid
Asked by
Billy
Top achievements
Rank 1
Answers by
Vasil
Telerik team
Billy
Top achievements
Rank 1
Robert
Top achievements
Rank 1
Share this question
or