I have a search box that takes an employee's last name and goes to a results page.
The results page takes the employee's last name from a query string and creates a GridView in code-behind to show all matches.
The GridView is working fine to show all matching employee's last names and first names. I'd like to add a third column to the GridView that contains a link to go to the employee's page. The link should have the employee's ID number in it.
Currently this third column is just showing the ID number, but I'm not sure how to make it a link in code-behind. Here's the code:
Private Sub loadDynamicGrid()
Dim connetionString As String
Dim connection As SqlConnection
Dim command As SqlCommand
Dim adapter As New SqlDataAdapter
Dim ds As New DataSet
Dim sql As String
Dim lastName As String
lastName = Request.QueryString("lastName")
connetionString = ConfigurationManager.ConnectionStrings("dbConnectionString").ConnectionString.ToString()
sql = "SELECT * FROM [EmployeeList] Where [lastname] like '" & lastName & "%' order by lastname"
connection = New SqlConnection(connetionString)
Try
connection.Open()
command = New SqlCommand(sql, connection)
adapter.SelectCommand = command
adapter.Fill(ds)
'Build Bound Columns
Dim curLastName As New BoundField
curLastName.HeaderText = "Last Name"
curLastName.DataField = "LastName"
GridView3.Columns.Add(curLastName)
Dim curFirstName As New BoundField
curFirstName.HeaderText = "First Name"
curFirstName.DataField = "FirstName"
GridView3.Columns.Add(curFirstName)
'This is the column that I want to add the link to
Dim employeeLink As New BoundField
employeeLink.HeaderText = ""
employeeLink.DataField = "EmplID"
GridView3.Columns.Add(employeeLink)
GridView3.Visible = True
GridView3.DataSource = ds
GridView3.DataBind()
adapter.Dispose()
command.Dispose()
connection.Close()
Catch ex As Exception
MsgBox("Can not open connection ! ")
End Try
End Sub
Thanks for any help!
The results page takes the employee's last name from a query string and creates a GridView in code-behind to show all matches.
The GridView is working fine to show all matching employee's last names and first names. I'd like to add a third column to the GridView that contains a link to go to the employee's page. The link should have the employee's ID number in it.
Currently this third column is just showing the ID number, but I'm not sure how to make it a link in code-behind. Here's the code:
Private Sub loadDynamicGrid()
Dim connetionString As String
Dim connection As SqlConnection
Dim command As SqlCommand
Dim adapter As New SqlDataAdapter
Dim ds As New DataSet
Dim sql As String
Dim lastName As String
lastName = Request.QueryString("lastName")
connetionString = ConfigurationManager.ConnectionStrings("dbConnectionString").ConnectionString.ToString()
sql = "SELECT * FROM [EmployeeList] Where [lastname] like '" & lastName & "%' order by lastname"
connection = New SqlConnection(connetionString)
Try
connection.Open()
command = New SqlCommand(sql, connection)
adapter.SelectCommand = command
adapter.Fill(ds)
'Build Bound Columns
Dim curLastName As New BoundField
curLastName.HeaderText = "Last Name"
curLastName.DataField = "LastName"
GridView3.Columns.Add(curLastName)
Dim curFirstName As New BoundField
curFirstName.HeaderText = "First Name"
curFirstName.DataField = "FirstName"
GridView3.Columns.Add(curFirstName)
'This is the column that I want to add the link to
Dim employeeLink As New BoundField
employeeLink.HeaderText = ""
employeeLink.DataField = "EmplID"
GridView3.Columns.Add(employeeLink)
GridView3.Visible = True
GridView3.DataSource = ds
GridView3.DataBind()
adapter.Dispose()
command.Dispose()
connection.Close()
Catch ex As Exception
MsgBox("Can not open connection ! ")
End Try
End Sub
Thanks for any help!