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

[Solved] How to Add Hyperlink to a column in RadGridView Control

7 Answers 614 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
satish
Top achievements
Rank 1
satish asked on 28 May 2009, 10:36 AM
Hi,

  Can any body help me how to add Hyperlink to a RadGridView column. I am binding the Table column to the grid like below.

<

 

telerikGridView:GridViewDataColumn HeaderText="PurchasingWebServiceURL" DataMemberBinding="{Binding PurchasingWebServiceURL}" />

Now My requirement is I  want to bind this column as an Hyperlink coulmn. By clicking on that column i have to navigate to the same URL (which is available in the column).

 


Can anybody please help me on this. It's Very urgent.

Thanks In advance for your time.

Regards
Satish
 

7 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 28 May 2009, 11:35 AM
Hi Satish,

Please check this demo:
http://demos.telerik.com/silverlight/#GridView/ColumnTypes/TemplateAndUnbound

Other possible approach is to use CellTemlate directly instead of Style.

Regards,
Vlad
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.
0
satish
Top achievements
Rank 1
answered on 28 May 2009, 12:13 PM
Hi Vlad,
   Thanks for the response.
   I have written like this. But I am getting the following error in very first line.

The attachable property "CellStyle" was not found in type 'GridViewDataColumn'

 

 

<telerikGridView:GridViewDataColumn.CellStyle>

 

 

 

<Style TargetType="telerikGridView:GridViewCell">

 

 

 

<Setter Property="Template">

 

 

 

<Setter.Value>

 

 

 

<ControlTemplate TargetType="telerikGridView:GridViewCell">

 

 

 

<Border BorderThickness="{TemplateBinding BorderThickness}"

 

 

BorderBrush="{TemplateBinding BorderBrush}"

 

 

Background="{TemplateBinding Background}">

 

 

 

<StackPanel Margin="10">

 

 

 

<HyperlinkButton Content="{Binding Name}" TargetName="_blank"

 

 

NavigateUri="{Binding Url}" />

 

 

 

<TextBlock HorizontalAlignment="Left" Width="400" Text="{Binding Description}" TextWrapping="Wrap" />

 

 

 

</StackPanel>

 

 

 

</Border>

 

 

 

</ControlTemplate>

 

 

 

</Setter.Value>

 

 

 

</Setter>

 

 

 

<Setter Property="BorderThickness" Value="0,0,1,1"/>

 

 

 

</Style>

 

 

 

</telerikGridView:GridViewDataColumn.CellStyle>
Could you please help me on this.

Regards
Satish

 

0
Vlad
Telerik team
answered on 28 May 2009, 12:55 PM
Hello Satish,

Here is an example:
<UserControl x:Class="SilverlightGrid.MainPage" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
    xmlns:telerikGridView="clr-namespace:Telerik.Windows.Controls.GridView;assembly=Telerik.Windows.Controls.GridView" 
    xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"
    <Grid> 
        <Grid.RowDefinitions> 
            <RowDefinition Height="30" /> 
            <RowDefinition /> 
        </Grid.RowDefinitions> 
        <Button Content="Submit changes" Click="Button_Click"/> 
        <telerik:RadGridView x:Name="RadGridView1" Grid.Row="1"
            <telerik:RadGridView.Columns> 
                <telerik:GridViewColumn> 
                    <telerik:GridViewColumn.CellStyle> 
                        <Style TargetType="telerikGridView:GridViewCell"
                            <Setter Property="Template"
                                <Setter.Value> 
                                    <ControlTemplate TargetType="telerikGridView:GridViewCell"
                                        <Border BorderThickness="{TemplateBinding BorderThickness}"  
                                            BorderBrush="{TemplateBinding BorderBrush}"  
                                            Background="{TemplateBinding Background}"
                                            <StackPanel Margin="10"
                                                <HyperlinkButton Content="{Binding Name}" TargetName="_blank"  
                                            NavigateUri="{Binding Url}" /> 
                                                <TextBlock HorizontalAlignment="Left" Width="400" Text="{Binding Description}" TextWrapping="Wrap" /> 
                                            </StackPanel> 
                                        </Border> 
                                    </ControlTemplate> 
                                </Setter.Value> 
                            </Setter> 
                            <Setter Property="BorderThickness" Value="0,0,1,1"/> 
                        </Style> 
                    </telerik:GridViewColumn.CellStyle> 
                </telerik:GridViewColumn> 
            </telerik:RadGridView.Columns> 
        </telerik:RadGridView> 
    </Grid> 
</UserControl> 
 


All the best,
Vlad
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.
0
satish
Top achievements
Rank 1
answered on 28 May 2009, 01:11 PM
Hi Vlad,

  I did the same. Eventhough I am getting the error. After That i have changed it to as per below

<

 

telerikGridView:GridViewColumn Width="100" HeaderText="PurchasingWebServiceURL" >

 

 

 

<telerikGridView:GridViewColumn.CellTemplate>

 

 

 

<DataTemplate>

 

 

 

<HyperlinkButton Content="{Binding PurchasingWebServiceURL}" NavigateUri="{Binding PurchasingWebServiceURL}" TargetName="_blank" ></HyperlinkButton>

 

 

 

</DataTemplate>

 

 

 

</telerikGridView:GridViewColumn.CellTemplate>

 

 

 

</telerikGridView:GridViewColumn>

Now it's showing perfectly in the grid. When I click on Hyperlink i am getting following error.

Sys.InvalidOperationException: ManagedRuntimeError error #4004 in control 'Silverlight1': System.NotSupportedException: Cannot navigate to locations relative to a page.
   at System.Windows.Controls.HyperlinkButton.GetAbsoluteUri()
   at System.Windows.Controls.HyperlinkButton.Navigate()
   at System.Windows.Controls.HyperlinkButton.OnClick()
   at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
   at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)
   at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)

Please help me on this.

Thanks & Kind Regards
Satish

 

0
Vlad
Telerik team
answered on 29 May 2009, 05:53 AM
Hi Satish,

Please check this thread for more info:
http://silverlight.net/forums/t/12073.aspx

Regards,
Vlad
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.
0
satish
Top achievements
Rank 1
answered on 01 Jun 2009, 12:06 PM
Hi,

   I have checked the link provided by you. But it's not helpful for me.
   Below is the code which I have added in XAML page.
 
<telerikGridView:GridViewColumn Width="100" HeaderText="PurchasingWebServiceURL" >  
               <telerikGridView:GridViewColumn.CellTemplate>  
                  <DataTemplate>  
                     <HyperlinkButton x:Name="HomeLink" Content="{Binding PurchasingWebServiceURL}" NavigateUri="{Binding PurchasingWebServiceURL}"  ClickMode="Press" TargetName="_blank"></HyperlinkButton>  
                  </DataTemplate>  
               </telerikGridView:GridViewColumn.CellTemplate>  
            </telerikGridView:GridViewColumn> 

I can't able to navigate to the URL.

I am getting the same error.
Sys.InvalidOperationException: ManagedRuntimeError error #4004 in control 'Silverlight1': System.NotSupportedException: Cannot navigate to locations relative to a page.  
   at System.Windows.Controls.HyperlinkButton.GetAbsoluteUri()  
   at System.Windows.Controls.HyperlinkButton.Navigate()  
   at System.Windows.Controls.HyperlinkButton.OnClick()  
   at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)  
   at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)  
   at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName) 

Can anybody please help me on this.

Regards
Satish

0
Michael
Top achievements
Rank 1
answered on 08 Jun 2009, 01:05 PM
Hi Satish,

I was also getting this error, however I was able fix mine by appending an "http://" to the URI

To do this I had to alter my datasource item wrapper a bit. here is my code:


public sting WebSiteUri
{
get
{

 

string webSite = <set Website here>;
if ( website != null && website.Trim() != "")
{
if (!website.StartsWith("http://", StringComparison.OrdinalIgnoreCase))
website = string.format(http://{0}, website);
}
return website;
}
}

hopefully this will help

 

Tags
GridView
Asked by
satish
Top achievements
Rank 1
Answers by
Vlad
Telerik team
satish
Top achievements
Rank 1
Michael
Top achievements
Rank 1
Share this question
or