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

GridHyperLinkColumn trim both url and text

1 Answer 159 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 2
Paul asked on 30 May 2009, 03:38 AM
Hi

I am trying to figure out how to trim the trailing spaces off the Url and the Text fields.   Both are coming from a linqdatasource.

I have tried a couple things but without success.

Hope someone can lead me in the right direction.

Thanks Paul
 
                            <telerik:GridHyperLinkColumn DataNavigateUrlFields="Item_Info_Url" DataTextField="Item_Description" 
                                UniqueName="column" DataNavigateUrlFormatString="{0:G}"  
                                DataTextFormatString="{0:G}"
                            </telerik:GridHyperLinkColumn> 

1 Answer, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 30 May 2009, 02:22 PM
Hello Paul,

The RadGrid event, which is normally used to modify stuff related to the datasource is ItemDataBound.


<%@ Page Language="C#" %> 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
 
<script runat="server"
 
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            HyperLink hl = (e.Item as GridDataItem)["MyHyperLinkColumn"].Controls[0] as HyperLink; 
            hlhl.NavigateUrl = hl.NavigateUrl.Trim(); 
        } 
    } 
     
</script> 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 
<html xmlns="http://www.w3.org/1999/xhtml"
<head runat="server"
<meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
<title>RadControls for ASP.NET AJAX</title> 
</head> 
<body> 
<form id="form1" runat="server"
<asp:ScriptManager ID="ScriptManager1" runat="server" /> 
 
<telerik:RadGrid 
    ID="RadGrid1" 
    runat="server" 
    AutoGenerateColumns="false" 
    DataSourceID="XmlDataSource1" 
    OnItemDataBound="RadGrid1_ItemDataBound"
    <MasterTableView> 
        <Columns> 
            <telerik:GridHyperLinkColumn 
                UniqueName="MyHyperLinkColumn" 
                HeaderText="HyperLinkColumn" 
                DataNavigateUrlFields="URL" 
                DataTextField="UrlText" 
                /> 
        </Columns> 
    </MasterTableView> 
</telerik:RadGrid> 
 
<asp:XmlDataSource ID="XmlDataSource1" runat="server"
<Data> 
<nodes> 
    <node URL="   http://www.telerik.com/  " UrlText="Telerik" /> 
    <node URL="   http://www.sitefinity.com/  " UrlText="Sitefinity" /> 
</nodes> 
</Data> 
</asp:XmlDataSource> 
 
</form> 
</body> 
</html> 



Kind regards,
Dimo
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Paul
Top achievements
Rank 2
Answers by
Dimo
Telerik team
Share this question
or