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

DataBind with HyperLink Column

3 Answers 218 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 31 Aug 2008, 09:32 AM
Hi,

I'm beginning to use RadGrid with a LinqDataSource. The binding of the grid works just fine. Now I want to insert a hyperlink-column into the grid which displays the name of a user and when it's clicked the user's profile page is displayed.

In my aspx file I added the column like this:
<telerik:GridHyperLinkColumn DataTextField="aspnet_User.UserName" HeaderText="User" DataNavigateUrlFields="http://google.de"
                    SortExpression="aspnet_User" UniqueName="aspnet_User">
 </telerik:GridHyperLinkColumn>

Now, the problem is, that there is no text displayed in the grid. It seems that
the DataTextField property is not working (but it is working in a GridBoundColumn).
Another problem is, how to prepare the NavigateUrl property to use the userId.

Edit: I tried to add the GridHyperLinkColumn Programmatically via the RadGrid_ItemDataBound() evend handler but it seems that the handler never
gets called.

Thanks in advance for any hints.
Best regards,
Robert

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 01 Sep 2008, 06:47 AM
Hi Robert,

Try setting the DataNavigateUrlFormatString property for the HyperLinkColumn as shown below.

ASPX:
<telerik:GridHyperLinkColumn DataNavigateUrlFields="CustomerID"  DataNavigateUrlFormatString="http://www.google.de/search?hl=en&amp;q={0}" DataTextField="CustomerID" HeaderText="CustomerID" UniqueName="CustomerID"
                    </telerik:GridHyperLinkColumn> 

You can also go through the following online demo to get details about the column types supported by RadGrid.
Column types

Shinu.
0
Robert
Top achievements
Rank 1
answered on 01 Sep 2008, 08:29 AM
Hi Shinu,

thank you for your hint. I already read the column types page. The code
which you posted does indeed display the hyperlink. Unfortunatly it doesn't
display anything (the line at the bottom of the grid cell is also not drawn) as
soon as I put the following in the DataTextField property:

DataTextField="aspnet_User.UserName"

When I use the same data binding with a GridBoundColumn instad of a GridHyperLinkColumn it works perfectly and displays the user name.

Best regards,
Robert
0
Princy
Top achievements
Rank 2
answered on 02 Sep 2008, 10:04 AM
Hi Robert,

I noticed that you are setting the sort expression to
SortExpression="aspnet_User"  . Instead  try setting it to
SortExpression="aspnet_User.UserName"

Thanks,
Princy
Tags
Grid
Asked by
Robert
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Robert
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or