DataGrid in dynamic hyperlinks

Hi folks I have a datagrid, with with a hyperlink coloumn, the hyperlink links to the same web page for all rows in the datagrid, I want the hyperlink to link to other pages based on data in the previous coloumn, Iv seen examples of how this has been done on the web but havent found an example when using with asp

The code I have so far is below

Dim ColoumnKey As New BoundColumn
 Dim ColoumnLink As New HyperLinkColumn

Conn = New _

            Cmd = New SqlCommand("SELECT ColoumnKey from test", Conn)
            SQLData = Cmd.ExecuteReader
DataGrid.DataSource = SQLData

            ColoumnKey.HeaderText = "ColoumnKey"
            ColoumnKey.DataField = "ColoumnKey"
            ColoumnLink.Navigation = "..\test.aspx"
            ColoumnLink.text = "Link"

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I would build my navigation string in my sql ..

something like:

SELECT ColoumnKey, '..\' + ColumnKey + '.aspx' as ColumnURL  from test


ColoumnLink.Navigation = "ColumnURL"  

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MrDavidThornAuthor Commented:
that would just link to a page called ColumnURL
MrDavidThornAuthor Commented:
its the attribute datanavigateUrlField, but you can do it via the SQL statement
off the top of my head, there are a couple of options besides setting the url via SQL (which is probably simplest):

change the link button column to a template field, and on the databound event of the gridview, iterate through the rows to set the postback url, something like :

for i as int16=0 to gridview.rows.count-1
ctype(findcontrol(gridview.rows(i),"lblCol3"),linkbutton).postbackurl="http://" & gridview.rows(i)(datacol).tostring

or, amend the evaluation of the link button's postback property to use the value of the appropriate field
Text='<%# Eval("http://"+"myfield) %>'
(please check the syntax of that, been a while since I've used the eval manually)
MrDavidThornAuthor Commented:
theory correct
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.