Hi ..
I have a problem in adding rows as link in hyperLinkField ..
How can i fill the hyperLinkField col by using while loop ?
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
dt = New DataTable()
col = New DataColumn("School Name")
dt.Columns.Add(col)
'Creat hyperLink as cloumn in gridview to display school name as link
hlink = New HyperLinkField
hlink.DataTextField = "School Name"
hlink.ControlStyle.Font.Underline = False
hlink.HeaderText = "School Name"
hlink.NavigateUrl = "schoolInfo.aspx"
GridView2.Columns.Add(hlink)
'initilize connection string
con.ConnectionString = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
sql = String.Format("(select name from school_site where school_id IN (SELECT school_id FROM favorite_schools WHERE user_name ='{0}')) UNION (select name from external_school where school_id IN (SELECT school_id FROM favorite_schools WHERE user_name ='{0}'))", Session("user_name"))
'Create Command object
Dim thisCommand As New SqlCommand(sql, con)
'connect to data base
con.Open()
Dim thisReader As SqlDataReader = thisCommand.ExecuteReader()
While thisReader.Read()
Row = dt.NewRow()
Row("School Name") = Convert.ToString(thisReader.GetValue(0))
dt.Rows.Add(Row)
End While
GridView2.DataSource = dt
GridView2.DataBind()
con.Close()
thisReader.Close()
End Sub
I have a problem in adding rows as link in hyperLinkField ..
How can i fill the hyperLinkField col by using while loop ?
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
dt = New DataTable()
col = New DataColumn("School Name")
dt.Columns.Add(col)
'Creat hyperLink as cloumn in gridview to display school name as link
hlink = New HyperLinkField
hlink.DataTextField = "School Name"
hlink.ControlStyle.Font.Underline = False
hlink.HeaderText = "School Name"
hlink.NavigateUrl = "schoolInfo.aspx"
GridView2.Columns.Add(hlink)
'initilize connection string
con.ConnectionString = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
sql = String.Format("(select name from school_site where school_id IN (SELECT school_id FROM favorite_schools WHERE user_name ='{0}')) UNION (select name from external_school where school_id IN (SELECT school_id FROM favorite_schools WHERE user_name ='{0}'))", Session("user_name"))
'Create Command object
Dim thisCommand As New SqlCommand(sql, con)
'connect to data base
con.Open()
Dim thisReader As SqlDataReader = thisCommand.ExecuteReader()
While thisReader.Read()
Row = dt.NewRow()
Row("School Name") = Convert.ToString(thisReader.GetValue(0))
dt.Rows.Add(Row)
End While
GridView2.DataSource = dt
GridView2.DataBind()
con.Close()
thisReader.Close()
End Sub