简体   繁体   English

将SQL值传递给asp.net HyperLink

[英]Pass SQL value to asp.net HyperLink

I want to have a Go Back link which goes to a page using a query string. 我想有一个使用查询字符串转到页面的“返回”链接。

<asp:HyperLink ID="backLink" runat="server" NavigateUrl="../project.aspx?id={0}"></asp:HyperLink>

I use a SqlDataReader elsewhere on my page so decided to use this to grab the ID that I wanted to pass to this hyperlink. 我在页面上的其他地方使用了SqlDataReader ,因此决定使用它来获取要传递给此超链接的ID。 The issue is when I tried to pass the value to this URL I kept getting errors that I was trying to convert int to string and no matter what I tried in converting it, it wouldn't allow me to use it. 问题是,当我尝试将值传递给此URL时,我不断收到尝试将int转换为字符串的错误,无论我尝试如何将其转换为字符串,都不允许我使用它。

I also tried something like this: 我也尝试过这样的事情:

<asp:HyperLink ID="backLink" runat="server" NavigateUrl="../project.aspx?id=<%=variableName%>"></asp:HyperLink>

That didn't work either. 那也不起作用。 It literally printed it instead of grabbing the value which might be because it was enclosed in double quotes? 它实际上是打印出来的,而不是获取可能是因为将其括在双引号中的值?

What is the best way to grab an int (Column is configured as an int) from a SQL table and then pass that to asp.net in a way similar to the above? 从SQL表中获取一个int(将列配置为int),然后以类似于上述方式将其传递给asp.net的最佳方法是什么?

在您的代码隐藏(Page_Load)中,尝试以下操作:

this.backLink.NavigateUrl = "../project.aspx?id=" + yourID.ToString();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM