DataGrid in vb.net dynamic hyperlinks

Hi folks I have a datagrid, asp.net 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 vb.net with asp

The code I have so far is below


Dim ColoumnKey As New BoundColumn
 Dim ColoumnLink As New HyperLinkColumn

Conn = New _
               SqlConnection(ConfigurationSettings.AppSettings("SQLConnectionString"))
            Conn.Open()

            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

MrDavidThornAsked:
Who is Participating?
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.

vossjckCommented:
I would build my navigation string in my sql ..

something like:

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

then

ColoumnLink.Navigation = "ColumnURL"  
0

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
0
MrDavidThornAuthor Commented:
its the attribute datanavigateUrlField, but you can do it via the SQL statement
0
mr_nadgerCommented:
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
next

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)
0
MrDavidThornAuthor Commented:
theory correct
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.