While sqlRdr.Read()
Dim _name As String = sqlRdr("name")
Dim _deptName As String = sqlRdr("departmentname")
Dim _sta As String = sqlRdr("sta")
Dim _stadate As String = sqlRdr("stadate")
data += "<tr><td>" & _name & "</td><td>" & _deptName & "</td><td>" & _sta & "</td><td>" & _stadate & "</td></tr>"
End While
I want to make 1st column as hyperlink and redirect to another page with value some thing like <td><a href="Account_Employee_Details.asp?ID=" & _name & "></a></td> but giving error "End of statement expected"
Public Function empData() As String
Dim Data As String = ""
Dim strS, strSql As String
strS = "Data Source=(localDb)\MSSQLLocalDB;Initial Catalog=aspnet-TestApplicationWithDatabase-20190820030542;Integrated Security=true"
Dim conn As SqlConnection = New SqlConnection(strS)
conn.Open()
strSql = "select * from People"
Dim sqlCommand As SqlCommand = New SqlCommand(strSql, conn)
Dim objRader As SqlDataReader = sqlCommand.ExecuteReader()
While objRader.Read()
Dim _name As String = objRader.GetString(0)
Dim _deptName As String = objRader.GetString(1)
Dim _sta As String = objRader.GetString(2)
Dim _stadate As String = objRader.GetString(3)Data += "<tr><td><a href='2163656.aspx?ID='" & _name & "''>" & _name & "</a></td><td>" & _deptName & "</td><td>" & _sta & "</td><td>" & _stadate & "</td></tr>"
End While
conn.Close()
Return Data
End Function
ASP.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today. Learn more >
Member
22 Points
82 Posts
Html table hyperlink
Mar 12, 2020 11:30 AM|kafsar|LINK
I have a table on ASP.net page,
<table class="table-responsive" bordercolor="#000000" width="100%" height="Auto">
<tr bgcolor="#00CCFF" style="border-color:transparent">
<td width="200">Employee Name</td>
<td width="200">Department</td>
<td width="40">Status</td>
<td width="100">Last Activity</td>
</tr><%=empData()%>
</table>
** Code behind **
While sqlRdr.Read()
Dim _name As String = sqlRdr("name")
Dim _deptName As String = sqlRdr("departmentname")
Dim _sta As String = sqlRdr("sta")
Dim _stadate As String = sqlRdr("stadate")
data += "<tr><td>" & _name & "</td><td>" & _deptName & "</td><td>" & _sta & "</td><td>" & _stadate & "</td></tr>"
End While
I want to make 1st column as hyperlink and redirect to another page with value some thing like <td><a href="Account_Employee_Details.asp?ID=" & _name & "></a></td> but giving error "End of statement expected"
Help please
All-Star
53691 Points
24030 Posts
Re: Html table hyperlink
Mar 12, 2020 02:26 PM|mgebhard|LINK
I recommend using standard ASP.NET Web Forms bound server controls like the DataGrid rather than string concatenation.
Contributor
4040 Points
1568 Posts
Re: Html table hyperlink
Mar 13, 2020 05:16 AM|yij sun|LINK
Hi kafsar,
Accroding to your description,I suggest you could use getstring method to read the data.It will get the value of the specified column as a string.
More details,you could refer to below codes:
ASPX:
Code-behind:
Result:
More details,you could refer to below article:
https://stackoverflow.com/questions/13860490/show-data-in-asp-net-html-table
Best regards,
Yijing Sun