locked
Html table hyperlink RRS feed

  • Question

  • User-49671077 posted

    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

    Thursday, March 12, 2020 11:30 AM

All replies

  • User475983607 posted

    I recommend using standard ASP.NET Web Forms bound server controls like the DataGrid rather than string concatenation.

    Data += "<tr><td><a href='Account_Employee_Details.asp?ID= " &
        _name & "'>" & _name & "</a></td><td>" &
        _deptName & "</td><td>" &
        _sta & "</td><td>" &
        _stadate & "</td></tr>"

    Thursday, March 12, 2020 2:26 PM
  • User1535942433 posted

    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:

      <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:

     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

    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

    Friday, March 13, 2020 5:16 AM