How to use Tag Clouds in the web page

In this article, I will share the logic for "How to use tag clouds in the web page" that I have used in one of my website that I have developed.There can be any way to do this tag cloud. In my logiv i have made a link to each tag and this will take me to the respective page i want.


A tag cloud is a visual depiction of tags used on a website. More frequently used tags are displayed in a larger font , with more bright colour(That will be as per the requirement). For example users of a web application might use one particular word more frequently and that need to be shown to every user of the application. In this case tag clouds will help us better. Hence making the website more user friendly, so that user can directly select from the tag clouds instead of trying or selecting words.
In this article, I will share the logic that I have used in one of my website that I have developed.

'This function is used to get the tag cloud details.
Public Function GetTagCloudDetails(ByVal strTag As String) As String
Dim dsTagClouds As New DataSet
Dim intEventId As Integer
Dim dvCloudData As New DataView
Const SpacerMarkup As String = " " 'The markup injected between each item in the cloud
Dim FontScale() As String = {"small", "medium", "large", "x-large", "xx-large"}
Dim dtClouds As DataTable
Dim intMaxWeight, intMinWeight As Integer
Dim scaleUnitLength As Decimal
Dim numProductsObj As Object
Dim numProductsDec As Decimal
Dim scaleValue As Integer
'Dim strValue As String
'strValue = Session("strSearchType")
Dim TextColumnName As String = ""
Dim NavigateUrlColumnName As String = ""
Dim NavigateUrlFormatString As String = ""
Dim strvalue As String = ""
intEventId = ConfigurationManager.AppSettings("USEventId")
' The below statement is to get some tag related details from the database.
dsTagClouds = BusinessLayer.Controller.DashboardSlideImagesController.GetTagDetails(intEventId, strTag)
If dsTagClouds Is Nothing Then
'tblAlertdisplay.Visible = True
'DisplayAlert.ShowMessage("ERROR", 2000)
ElseIf dsTagClouds.Tables.Count = 0 Then
CloudMarkup.Text = Nothing
Return strTag
'Actual logic commencess.
dtClouds = dsTagClouds.Tables(0)
intMaxWeight = dsTagClouds.Tables(1).Rows(0)(0)
intMinWeight = dsTagClouds.Tables(1).Rows(0)(1)
dsTagClouds = Nothing
NavigateUrlFormatString = "../../aspx/US/ConfluenceUSSearchPeople.aspx?strSearchValue={0}&strSearchType=" + strTag
CloudMarkup.Text = Nothing
dvCloudData = dtClouds.DefaultView
TextColumnName = "txtValue"
NavigateUrlColumnName = "txtValue"
scaleUnitLength = (intMaxWeight - intMinWeight + 1) / Convert.ToDecimal(FontScale.Length)
For Each row As DataRowView In dvCloudData
numProductsObj = row("intCount")
If row(NavigateUrlColumnName).ToString().Contains("&") Then
strvalue = row(NavigateUrlColumnName).ToString().Replace("&", "_")
' row(NavigateUrlColumnName) = strvalue
strvalue = row(NavigateUrlColumnName).ToString()
End If
If Not Convert.IsDBNull(numProductsObj) Then
numProductsDec = Convert.ToDecimal(numProductsObj)
scaleValue = Math.Truncate((numProductsDec - intMinWeight) / scaleUnitLength)
CloudMarkup.Text &= String.Format("{2}{3}", _
Page.ResolveUrl(String.Format(NavigateUrlFormatString, Server.HtmlEncode(strvalue))), _
FontScale(scaleValue), row(TextColumnName).ToString(), SpacerMarkup)
End If
Return ""
numProductsObj = Nothing
dvCloudData = Nothing
End If
Catch exApp As ApplicationException
Return ""
Exit Function
Catch ex As Exception
Return ""
Exit Function
dsTagClouds = Nothing
dvCloudData = Nothing
numProductsObj = Nothing
End Try
End Function

Here CloudMarkup is an ASP literal.


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: