简体   繁体   中英

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. 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.

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?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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