Question : Code Behind Value in Hyperlink Field

I'm trying to obtain a value from a database in code-behind and pass it to a hyperlink inside a gridview to dynamically create a "click to" link.  Every time I try to use the variable from code-behind, It keeps literally translating the link.

Please advise as to how I can use a returned variable in the hyperlink field.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
Here's my code behind in the Page Load event: 
        string connString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
        SqlConnection conn = new SqlConnection(connString);
        conn.Open();
        SqlCommand command = conn.CreateCommand();
        command.CommandText = "Select FormPage From Forms Where UserID = '" + Membership.GetUser().ProviderUserKey + "'";
        string FormURL = command.ExecuteScalar().ToString(); 
And here's my hyperlink attempt inside the gridview control: 


                    
                    


Answer : Code Behind Value in Hyperlink Field

Try converting HyperlinkField into a TemplateField...this way you will have more control over the Hyperlink.
Then upon RowDataBound event Find the hyperlink and set its NavigateUrl in the code behind.

pseudo for RowDatabound:
HyperLink hl = (HyperLink) e.Row.FindControl("YourHypelinkID");
if(hl!=null)
{ hl.NavigateUrl = "set it to your value";
}

Hint: http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Studio_.NET_2005/Q_24653486.html
Random Solutions  
 
programming4us programming4us