This is a migrated thread and some comments may be shown as answers.
RadGrid not sorting properly Scandinavian charaters
5 Answers 38 Views
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 04 Jan 2010, 02:16 PM
Hello All,

I have a problem when sorting RadGrid which has Scandinavian characters (åäöÅÄÖ).
E.g. Columns below having following data are not handled correctly (sample case):

[Driver]  <-- Data not sorted properly -->
Räikkönen
Raikkonen
Åslund
Aslund

Rows Åslund and Räikkönen shuld be the last ones.

So, how could I tell RadGrid that it should support UTF-8 (or something else???) that sorting would work?

Below is my aspx and cs codesnippets

telerik:RadGrid ID="RadGridPersons" runat="server"
 AutoGenerateColumns="False" AllowFilteringByColumn="false" AllowSorting="True"
 SortingSettings-EnableSkinSortStyles="true" Width="80%" Visible="false"
 OnSortCommand="RadGridPersons_SortCommand" onitemdatabound="RadGridPersons_ItemDataBound">
 <MasterTableView CellSpacing="-1" TableLayout="Fixed" Width="100%"
 AllowNaturalSort="false" AllowMultiColumnSorting="false">   
  <SortExpressions>
    <telerik:GridSortExpression FieldName="LastName" SortOrder="Ascending" />
  </SortExpressions>      
 <RowIndicatorColumn>
  <HeaderStyle Width="20px"></HeaderStyle>
 </RowIndicatorColumn>
 <ExpandCollapseColumn>
 <HeaderStyle Width="20px"></HeaderStyle>
 </ExpandCollapseColumn>
  <Columns>    
   <telerik:GridBoundColumn DataField="CustomerId"
    HeaderText='<%$Resources:Customers, PersonCustomerSearchResultHeader_CustomerNumber%>'
    SortExpression="CustomerId" UniqueName="CustomerId" Visible="false">
   </telerik:GridBoundColumn>

   <telerik:GridHyperLinkColumn DataTextField="LastName"
    HeaderText='<%$Resources:Customers, PersonCustomerSearchResultHeader_LastName%>'
    SortExpression="LastName" UniqueName="LastName" DataNavigateUrlFields="CustomerId"
    DataNavigateUrlFormatString="PersonCustomer.aspx?CustomerId={0}" Visible="true"
    HeaderStyle-Width="90" HeaderStyle-Wrap="true" ItemStyle-Font-Italic="true"
    ItemStyle-Width="90" ItemStyle-Wrap="false">
   </telerik:GridHyperLinkColumn>


 
    protected void RadGridPersons_SortCommand(object source, Telerik.Web.UI.GridSortCommandEventArgs e)  
    {  
        GridDataItemCollection Coll = RadGridPersons.MasterTableView.Items;  
        var Items = from GridDataItem item in Coll  
                    orderby e.CommandSource ascending  
                    select new 
                    {  
                        CustomerId = item["CustomerId"].Text.ToString(),  
                        LastName = (item["LastName"].Controls[0] as HyperLink).Text.ToString(),  
                        ForeNames = item["ForeNames"].Text.ToString(),  
                        Street = item["Street"].Text.ToString(),  
                        PostalCode = item["PostalCode"].Text.ToString(),  
                        City = item["City"].Text.ToString(),  
                        SocialSecurityId = item["SocialSecurityId"].Text.ToString(),  
                        StatusKey = item["StatusKey"].Text.ToString(),  
                    };  
 
        RadGridPersons.DataSource =  
            (e.NewSortOrder == GridSortOrder.Ascending) ? Items : Items.OrderByDescending(x => x.LastName);  
 
        RadGridPersons.DataBind();  
    }  
 

Thanks,

Michael

 



5 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 04 Jan 2010, 04:25 PM
Hello Mike,

Generally RadGrid automatic operations are supported if the grid is bound using DataSourceID or NeedDataSource. Please handle NeedDataSource, assign desired DataSource for the grid and do not call DataBind().

I hope this helps.

All the best,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Mike
Top achievements
Rank 1
answered on 04 Jan 2010, 04:47 PM
Thanks, I will try NeedDataSource.

The reason why I'm using my code is that I would like to read data from memory not againg from database.

What is the best way to sort RadGrid without reading data everytime from database?

I was looking localization tecnique like below:
http://www.dnknormark.net/post/Set-the-DataTableLocale-property-or-get-weird-sorting.aspx

Cheers,

Michael
0
Accepted
Pavlina
Telerik team
answered on 05 Jan 2010, 02:38 PM
Hello Mike,

To achieve your goal you could save the data in session, ViewState or Cache(depending on the scope of the data).
However I am sending you a simple working project which handles the desired functionality.

I hope it gets you started properly.

Kind regards,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Mike
Top achievements
Rank 1
answered on 07 Jan 2010, 07:24 AM
Thank you Pavlina for your help!

I can use techniques like mentioed but still I'm wondering that are
there any drawbacks getting GridItems like code below?

 

 
GridDataItemCollection Coll = RadGridOrganizations.MasterTableView.Items;   
//.. Iterate DataItems in GridDataItemCollection into other Collection  
 

I also found the reason why Sorting was failed. I was running Web Application under SharePoint Context and SharePont's localization overrided all ASP.NET based SharePoint Application's settings. SharePoint Site which contains ASP.NET Application should be created with proper locale otherwise problems exists.


It is possible In ASP.NET C# code to use code like following to set your own Locale afterwards.


    // Param is like : fi-FI  
 
 
    public void SetLocale(string CultInfoString)   
 
    {  
 
          using (Microsoft.SharePoint.SPWeb web = Microsoft.SharePoint.SPContext.Current.Web)  
 
          {  
 
                   CultureInfo culture = new CultureInfo(CultInfoString);  
 
                   web.Locale = culture;  
 
                   web.AllowUnsafeUpdates = true;  
 
                   web.Update();  
 
                   web.AllowUnsafeUpdates = false;  
 
           }  
 
    }  
 

 

Quite complex environment but glad that it is solved :)


Best Regards

Michael

0
Pavlina
Telerik team
answered on 07 Jan 2010, 05:22 PM
Hello Mike,

You could try out the following code snippet for getting the item collection.
C#:
protected void RadGrid1_PreRender(object sender, EventArgs e)  
{  
    GridItemCollection item = RadGrid1.MasterTableView.Items;  
}

Kind regards,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Mike
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Mike
Top achievements
Rank 1
Share this question
or