如何创建一个超链接字段进行SQL查询 [英] How to create a HyperLink field out of SQL query
本文介绍了如何创建一个超链接字段进行SQL查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在参考我的这个问题,
我有一个GridView它看起来像这样此刻,
下面是SQL 小提琴一>
问:
我如何创建FruitTitle一个HyperLinkField字段和链接水果网站?
这是我使用的代码显示 Types_of_Fruits_in_Crate
的时刻和完美的作品,
的BoundField theField =新的BoundField();
theField.DataField =Types_of_Fruits_in_Crate;
gv.Columns.Add(theField);
要放什么东西在
HyperLinkField字段theField =新HyperLinkField字段();
theField.DataTextField ='Types_of_Fruits_in_Crate';
theField.DataNavigateUrlFields = //不知道......
解决方案
使用文字的控制,而不是超链接,然后尝试使用下面的查询:
SELECT CrateTitle,CrateDescription,CrateID,
的东西(
(
选择'< A HREF ='''+ FruitWebsite] +'''的目标='_空白''>'+ FruitTitle] +'< / A>'
从水果WHERE CrateID = t.CrateID FOR XML路径('')
),1,1,'')Types_of_Fruits_in_Crate
FROM(SELECT DISTINCT CrateTitle,CrateDescription,CrateID从水果)笔
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 ....
解决方案
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
这篇关于如何创建一个超链接字段进行SQL查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文