How to create a HyperLink field out of SQL query
c#, gridview, webforms
Solution
Use Literal control instead of Hyperlink and then try using below Query:
SELECT CrateTitle,CrateDescription,CrateID,
stuff(
(
SELECT '<a href=''' + [FruitWebsite] + ''' target=''_blank''>'+ [FruitTitle] +'</a>'
FROM fruits WHERE CrateID = t.CrateID FOR XML path('')
),1,1,' ') Types_of_Fruits_in_Crate
FROM (SELECT DISTINCT CrateTitle,CrateDescription,CrateID FROM fruits )t
Problem
In reference to this question of mine, GridView Table 1 related to Table 2 I got a gridview which looks like this at the moment, Here is the SQL fiddle Question: How Can I create a HyperLinkField with FruitTitle and link to fruit website ? This is the code I am using for displaying `Types_of_Fruits_in_Crate` at the moment and works perfectly, ``` BoundField theField = new BoundField(); theField.DataField = "Types_of_Fruits_in_Crate"; gv.Columns.Add(theField); ``` what to put in ``` HyperLinkField theField = new HyperLinkField(); theField.DataTextField = 'Types_of_Fruits_in_Crate'; theField.DataNavigateUrlFields = // not sure .... ```