从数据库中提取数据并在asp.net中显示为超链接

时间:2021-02-03 09:52:02

Im developing an ASP.net application and Im having trouble finding out how to pull data from my database and display the resulting data as hyperlinks. Basically I need to pull the data and display it as a series of hyperlinks which when clicked will redirect the user to the corresponding page. Could anyone please point me in the right direction (tutorials,articles etc)

我正在开发一个ASP.net应用程序,我很难找到如何从我的数据库中提取数据并将结果数据显示为超链接。基本上我需要拉取数据并将其显示为一系列超链接,点击这些超链接会将用户重定向到相应的页面。任何人都可以指出我正确的方向(教程,文章等)

Many thanks.

2 个解决方案

#1


0  

From your post I'd guess you have little to no html knowledge. I can't give you the technical solution without writing it for you but you need to retrieve the hyperlink value from the database and place these into hyperlink tags for your page.

从你的帖子我猜你几乎没有HTML知识。如果没有为您编写技术解决方案,我无法为您提供技术解决方案,但您需要从数据库中检索超链接值并将其放入页面的超链接标记中。

I'd start here with html and retrieving the sql data: http://www.w3schools.com/

我从这里开始使用html并检索sql数据:http://www.w3schools.com/

#2


0  

Well without knowing exactly what data your pulling from the database, im going to take a stab in the dark and recommend the following.

好吧,如果你不确切知道从数据库中提取什么数据,我会在黑暗中采取刺,并推荐以下内容。

Set up a stored procedure which retrieves the required information, then execute this procdure using a sqlDataReader and for each result stick some values within tags?

设置一个存储过程来检索所需的信息,然后使用sqlDataReader执行此过程,并为每个结果添加一些标记内的值?

So something like the following:

如下所示:

while (rdr.Read())
{
    string name= rdr["name"].ToString();
    string link= rdr["link"].ToString();
    HtmlAnchor htmlanchor = new HtmlAnchor();
    htmlanchor.HRef = link;
    htmlanchor.InnerText = name;
    formID.Controls.Add(htmlanchor);
}

#1


0  

From your post I'd guess you have little to no html knowledge. I can't give you the technical solution without writing it for you but you need to retrieve the hyperlink value from the database and place these into hyperlink tags for your page.

从你的帖子我猜你几乎没有HTML知识。如果没有为您编写技术解决方案,我无法为您提供技术解决方案,但您需要从数据库中检索超链接值并将其放入页面的超链接标记中。

I'd start here with html and retrieving the sql data: http://www.w3schools.com/

我从这里开始使用html并检索sql数据:http://www.w3schools.com/

#2


0  

Well without knowing exactly what data your pulling from the database, im going to take a stab in the dark and recommend the following.

好吧,如果你不确切知道从数据库中提取什么数据,我会在黑暗中采取刺,并推荐以下内容。

Set up a stored procedure which retrieves the required information, then execute this procdure using a sqlDataReader and for each result stick some values within tags?

设置一个存储过程来检索所需的信息,然后使用sqlDataReader执行此过程,并为每个结果添加一些标记内的值?

So something like the following:

如下所示:

while (rdr.Read())
{
    string name= rdr["name"].ToString();
    string link= rdr["link"].ToString();
    HtmlAnchor htmlanchor = new HtmlAnchor();
    htmlanchor.HRef = link;
    htmlanchor.InnerText = name;
    formID.Controls.Add(htmlanchor);
}