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

Automatic URL Encoding?

6 Answers 390 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Augusto
Top achievements
Rank 1
Augusto asked on 09 Mar 2010, 12:31 PM
Hello,

I have a lot of Grids that display correctly strings from a database that contains Chinese and Japanese characters as well as German and French accents. I have to build links from this items in the Grids to display the details in another page.

The URL passed to the new page has the Chinese/Japanese/etc characters: http://test.aspx?Os=Microsoft Windows 7 旗舰版

Because the way IE works I need this URL to be encoded or when I read back the Os variable it will return the value Microsoft Windows 7 ????.

I know I can accomplish this via the following Sub:

Protected Sub MyGrid_ItemDataBound(ByVal sender As ObjectByVal e As Telerik.Web.UI.GridItemEventArgs) Handles MyGrid.ItemDataBound  
        If e.Item.ItemType = GridItemType.Item Or e.Item.ItemType = GridItemType.AlternatingItem Then 
            Dim dataItem As GridDataItem = CType(e.Item, GridDataItem)  
            Dim currentRow As DataRowView = DirectCast(e.Item.DataItem, DataRowView)  
            For Each col As GridColumn In RadgridWinServerOSCount.Columns  
                If col.UniqueName = "columnOS" Then 
                    Dim strTxt As String = currentRow.Row("Operating_System").ToString  
                    Dim NewUrl As String 
                    NewUrl = Server.UrlEncode(strTxt)  
                    CType(dataItem("columnOS").Controls(0), HyperLink).NavigateUrl = "~/test.aspx?Os=" & NewUrl  
                End If 
            Next 
        End If 
    End Sub 

However this is kind of unpractical as the application I'm handling have around 25 different Grids where this needs to be changed, hence, even by creating a function to re-write the URL it's going to require a lot of code and the maintenance would be too cumbersome.

I was wondering if there's a way to "automatically" URL encode the GridHyperLinkColumn items in the Grid, I looked throught the documentation but I couldn't find anything relevant. I think to optionally allow this encoding for GridHyperLinkColumn would be really handy.

Thanks!

6 Answers, 1 is accepted

Sort by
0
Accepted
Tsvetoslav
Telerik team
answered on 12 Mar 2010, 08:04 AM
Hi Augusto,

Such a feature is not available in the hyperlink column of RadGrid and I am afraid the code-behind solution is the only one available.

Regards,
Tsvetoslav
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Augusto
Top achievements
Rank 1
answered on 12 Mar 2010, 12:18 PM
Thanks Tsvetoslav,

I suspected that. Will it be possible for you guys to consider adding a feature for RadGrid to enable URL encoding as an option? It will be a great addition for those people that need Japanese, Chinese, Cirilyc language sets and use IE.

Thanks,

Augusto.
0
Tsvetoslav
Telerik team
answered on 17 Mar 2010, 02:25 PM
Hi Augusto,

Unfortunately, for the time being our development team has deemed it not necessary to implement such a feature. However, if more customers express an interest in it we will give it due consideration.

Regards,
Tsvetoslav
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Tyson
Top achievements
Rank 1
answered on 28 Jan 2013, 02:09 PM
You can also try inheriting from the GridHyperlinkColumn

I'm trying something along these lines. Haven't started testing yet, so we'll see how it goes...

public class GridEncodableHyperlinkColumn : GridHyperLinkColumn {
 
        public bool URLEncodeLinks { get; set; }
 
        public GridEncodableHyperlinkColumn() : base() {
            URLEncodeLinks = true;
        }
 
        protected override string FormatDataNavigateUrlValue(object[] dataUrlValues) {
            if (URLEncodeLinks) {
                for (int i = 0; i < dataUrlValues.Length; i++ ) {
                    if (dataUrlValues[i] != null && dataUrlValues[i] is string && !string.IsNullOrEmpty((string)dataUrlValues[i])) {
                        string dataUrlValue = HttpContext.Current.Server.UrlEncode((string)dataUrlValues[i]);
                        dataUrlValues[i] = dataUrlValue;                     
 
                    }
                }
            }
 
            return base.FormatDataNavigateUrlValue(dataUrlValues);
        }
    }

...then just use that instead of the GridHyperLinkColumn.
0
John
Top achievements
Rank 1
answered on 04 Jul 2013, 09:14 PM
Hi, is it still the case that in the latest version of the GridHyperLinkColumn it does not URL encode the DataNavigateUrlFields, so I have to do this myself manually eg in code behind?

If so, please consider adding this capability as it is rather clumsy to do manually when the whole point of the DataNavigateUrlFields and DataNavigateUrlFormatString properties is for the control config to be 100% declarative.

Thanks
0
Tsvetoslav
Telerik team
answered on 09 Jul 2013, 01:15 PM
Hello John,

This feature is not on our to-do list. Please, share your feedback at:
http://www.telerik.com/feedback.aspx
 
Regards,
Tsvetoslav
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Augusto
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Augusto
Top achievements
Rank 1
Tyson
Top achievements
Rank 1
John
Top achievements
Rank 1
Share this question
or