Click here to Skip to main content
15,917,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please check the following code.

I want to bind hyperlink to the gridview column1. The column comes from DataSet.
How to bind hyperlink to the ds and how to bind to grid view?

con = DBconnection.getconnection()
        ds = BLLFactory.coursebooks3().course()
        If ds.Tables(0).Rows.Count > 0 Then
            For j = 0 To ds.Tables(0).Rows.Count - 1


                hfield = New HyperLinkField()
                hfield.HeaderText = ds.Tables(0).Rows(j)(1)
                hfield.NavigateUrl = "somepage.aspx"
             hfield.DataTextField = ds.Tables(0).Rows(j)(1).ToString()
                GridView1.Columns.Add(hfield)
                bfield1 = New BoundField()
                bfield1.HeaderText = ds.Tables(0).Rows(j)(1)
                bfield1.DataField = ds.Tables(0).Rows(j)(1).ToString()


                GridView1.Columns.Add(bfield1)
                'GridView1.DataSource = ds.Tables(0)
                GridView1.DataBind()
            Next

        End If
    End Sub
Posted
Updated 8-Sep-10 23:20pm
v4
Comments
Dalek Dave 9-Sep-10 5:06am    
Edited for Grammar and Code Block.
Ankur\m/ 9-Sep-10 5:13am    
What is the problem with the code? Do you get any errors?
Sandeep Mewara 9-Sep-10 5:16am    
@DD : you forgot to change the title! :) ... atleast this one for sure needed a change!
Ankur\m/ 9-Sep-10 5:22am    
I changed it! :)
Venubabu, click 'Improve question' and see how giving an appropriate subject to your question gives you with relevant answers at that very moment.
venubabu k 9-Sep-10 5:24am    
what do u mean.

1 solution

I think you must use
hfield.DataTextField = "NameOfTheFieldInDataSet"
and it will use the content of the field for the text of the hyperlink
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900