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

Sort Radgrid with column header contains comma (,) for auto generate column

3 Answers 175 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ranjith
Top achievements
Rank 1
Ranjith asked on 10 May 2011, 06:43 AM
Hi,

Im using Radgrid with AutoGenerateColumns="True" and the column header will be like "Firstname, Lastname" (with Comma). While sorting the grid on column (Firstname, Lastname) with sort expression field name it throws error like "Cannot find column Firstname". Im using the following code in RadGrid1_SortCommand.

GridSortExpression sortExpr = new GridSortExpression();
switch (e.OldSortOrder)
        {
            case GridSortOrder.None:
                sortExpr.FieldName = e.SortExpression;
                sortExpr.SortOrder = GridSortOrder.Descending;
                e.Item.OwnerTableView.SortExpressions.AddSortExpression(sortExpr);
                Session["GridSort"] = GridSortOrder.Descending;
                break;
            case GridSortOrder.Descending:
                sortExpr.FieldName = e.SortExpression;
                sortExpr.SortOrder = GridSortOrder.Ascending;
                e.Item.OwnerTableView.SortExpressions.AddSortExpression(sortExpr);
                Session["GridSort"] = GridSortOrder.Ascending;
                break;
            case GridSortOrder.Ascending:
                sortExpr.FieldName = e.SortExpression;
                sortExpr.SortOrder = GridSortOrder.Descending;
                e.Item.OwnerTableView.SortExpressions.AddSortExpression(sortExpr);
                Session["GridSort"] = GridSortOrder.Descending;
                break;
        }
e.Canceled = true;
RadGrid1.Rebind();

Sample Grid: (2nd Column Header contains Comma)

S.No FirstName, LastName DOB City
1 XXX, X 11/11/1111 NJ
2 YYY, Y 11/11/1111 NJ
3 ZZZ, Z 11/11/1111 NJ

Please Reply ASAP.
Thanks in Advance.

Thanks,
Ranjith J

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 10 May 2011, 08:27 AM
Hello Ranjith,

The following forum thread discusses the same scenario. As far as I know special characters are not supported in RadGrid field names. Check the thread for more details.

Sorting issue in RadGrid - columns start and end with brackets.

Thanks,
Princy.
0
Ranjith
Top achievements
Rank 1
answered on 10 May 2011, 08:38 AM
Thanks Princy.

Is there any alernate source to overcome the current scenario.

Thanks,
Ranjith J
0
Tsvetoslav
Telerik team
answered on 13 May 2011, 12:05 PM
Hello Ranjith,

What you are actually doing for the problematic column is assigning its DataField property to a coma separated string and that is not acceptable. Therefore, when retrieving the data from your underlying data-source just change the string containing field to another name. For example, if you have a SQL select statement, you should change it as follows:

Select S.No,    [FirstName, LastName] as FirstName_LastName,    DOB,    City FROM [yout table name goes here]

 Hope it helps.

All the best,
Tsvetoslav
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.

Tags
Grid
Asked by
Ranjith
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Ranjith
Top achievements
Rank 1
Tsvetoslav
Telerik team
Share this question
or