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

Bound Grid Column to External hyperlink

4 Answers 774 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jim
Top achievements
Rank 1
Jim asked on 21 Jul 2014, 04:06 PM
@(Html.Kendo().Grid<positions.Models.vOpenPositionsDistinct>()
.Name("gridMain")
.DataSource(dataSource => dataSource // Configure the grid data source
.Ajax() // Specify that ajax binding is used
.Read(read => read.Action("Positions_Read", "Home")) // Set the action method which will return the data in JSON format
)
.Columns(columns =>
{
columns.Bound(s => s.SourceURL).ClientTemplate("<a href='" + Url.Content("#= SourceURL #") + "' target='_blank'>#: SourceURL #</a>").HeaderTemplate("Source URL").Width(120);

})

I have external url links stored in my database and I want to bind them in a grid column as <a href> tag. If I use the code above all rows will have the 1st row SourceURL Value .

What am I doing wrong? It seems as if it creates a generic template for all rows and the template has same url.

4 Answers, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 22 Jul 2014, 07:24 AM
Hello Jim,


The sample code looks correct for displaying the unique URL for each Grid item. Could you please assure that the correct URLs are returned from the read action? If that is the case and the issue is still reproducing, please send me a small isolated project, which demonstrates it, so I could inspect it locally and assist further.

Regards,
Dimiter Madjarov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Jim
Top achievements
Rank 1
answered on 22 Jul 2014, 09:15 AM
Hi,

If I remove the ClientTemplate and only bind columns.Bound(s => s.SourceURL); I get the links the way they should be.
The links are from DB view vOpenPositions and the view returns the links the way they should be.

I have created a sample MSSQL Azure Database and a sample project here: https://www.dropbox.com/s/fvlwjq60bz20ijj/positions.zip

It should connect to the database straight way...

Thank you for your time!


n/a
Top achievements
Rank 1
commented on 17 May 2021, 08:17 PM

Hi, Can youi please provide the full view code where you got a workin example?
0
Accepted
Dimiter Madjarov
Telerik team
answered on 22 Jul 2014, 10:00 AM
Hello Jim,


Thank you for providing the sample project. The Grid was unable to fetch the data and an exception "No connection could be made because the target machine actively refused it" was thrown.

Nevertheless after reviewing the Index view I was able to spot the reason for the issue. I assume that you are referring to the child Grid SourceURL column. When a client template is used in a child Grid, the hash symbols should be escaped. Otherwise the Grid will try to find the property in the parent model. Usually this will result in a "Property not found" error, but in the specific current case the parent model contains a property with the same name and just displays it in all rows. As as solution, I would suggest to use backslashes to escape the hash symbols in the child Grid.
E.g.
columns.Bound(s => s.SourceURL).ClientTemplate("<a href='" + Url.Content("\\#= SourceURL \\#") + "' target='_blank'>\\#= SourceURL \\#Link</a>")

I hope this information helps.

Regards,
Dimiter Madjarov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Jim
Top achievements
Rank 1
answered on 22 Jul 2014, 11:36 AM
I am sorry for the DB issue, maybe some FW rule...

Your help is greatly appreciated!! Thanks! It all works now.
Tags
Grid
Asked by
Jim
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Jim
Top achievements
Rank 1
Share this question
or