Introduction:
Here I will explain how to create tag cloud in asp.net website using jQuery, c#, vb.net with example or generate tag cloud in asp.net with database using jQuery, c#, vb.net.
Here I will explain how to create tag cloud in asp.net website using jQuery, c#, vb.net with example or generate tag cloud in asp.net with database using jQuery, c#, vb.net.
Description:
In previous post I explained sitemap control example, send html page as mail body in asp.net, send mail with images using gmail user credentials, send multiple attachments with email in asp.net, how to send mail with attachment in asp.net and many more articles related to asp.net using c#, vb.net. Now I will explain how to how to create tag cloud in asp.net website using jQuery, c#, vb.net with example.
In previous post I explained sitemap control example, send html page as mail body in asp.net, send mail with images using gmail user credentials, send multiple attachments with email in asp.net, how to send mail with attachment in asp.net and many more articles related to asp.net using c#, vb.net. Now I will explain how to how to create tag cloud in asp.net website using jQuery, c#, vb.net with example.
To create tag cloud in
website first create new website and write follwing code in Default.aspx page
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Tag Cloud in Asp.net using C#</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(function()
{
$.ajax({
type: "POST",
url: "Default.aspx?type=gettags",
data: "{}",
success: function(data)
{
$('#tagsdiv').html(data);
},
error: function(result)
{
alert("Error");
}
});
});
</script>
<style type="text/css">
a.TagSize1
{
font-family: Arial;
font-size: 8px;
padding:3px;
color: #000;
}
a.TagSize2
{
font-family: Arial;
font-size: 12px;
padding:3px;
color: #000;
}
a.TagSize3
{
font-family: Arial;
font-size: 16px;
padding:3px;
color: #000;
}
a.TagSize4
{
font-family: Arial;
font-size: 20px;
padding:3px;
color: #000;
}
</style>
</head>
<body>
<form id="form1"
runat="server">
<div id="tagsdiv"
style="width:50px">
</div>
</form>
</body>
</html>
|
After completion of aspx page write the following code in
codebehind
C#
Code
using System;
using System.Data;
public partial class _Default :
System.Web.UI.Page
{
protected void
Page_Load(object sender, EventArgs e)
{
string type = Request["type"];
string ReturnDataType = "application/html"
;
if(type=="gettags")
{
string rJson = GetTagDetails();
Response.ContentType = ReturnDataType;
Response.Write(rJson);
Response.End();
}
}
public string
GetTagDetails()
{
DataTable dt = new DataTable();
dt.Columns.Add("Tagid",
typeof(Int32));
dt.Columns.Add("TagName",
typeof(string));
dt.Columns.Add("Noofarticles",
typeof(string));
dt.Rows.Add(1, "Asp.Net",
100);
dt.Rows.Add(2, "C#.Net",
10);
dt.Rows.Add(3, "SQL
Server", 30);
dt.Rows.Add(4, "jQuery",
20);
dt.Rows.Add(6, "javascript",
15);
dt.Rows.Add(7, "XSLT",
50);
string strleadDetails = string.Empty;
for (int i = 0; i <
dt.Rows.Count; i++)
{
int j = Convert.ToInt32(dt.Rows[i][2].ToString());
if (j <= 10)
{
strleadDetails += "<a
href=javascript:void(0) class=TagSize1>" + dt.Rows[i][1] + "</a>";
}
else if (j > 10 && j
<= 20)
{
strleadDetails += "<a
href=javascript:void(0) class=TagSize2>" + dt.Rows[i][1] + "</a>";
}
else if (j > 20 && j
<= 50)
{
strleadDetails += "<a
href=javascript:void(0) class=TagSize3>" + dt.Rows[i][1] + "</a>";
}
else if (j > 50 && j
<= 100)
{
strleadDetails += "<a
href=javascript:void(0) class=TagSize4>" + dt.Rows[i][1] + "</a>";
}
}
return strleadDetails;
}
}
|
VB.NET Code
Imports System.Data
Partial Class vbcode
Inherits System.Web.UI.Page
Protected Sub
Page_Load(ByVal sender As Object, ByVal e As
EventArgs) Handles Me.Load
Dim type As String = Request("type")
Dim ReturnDataType As String = "application/html"
If type = "gettags"
Then
Dim rJson As String = GetTagDetails()
Response.ContentType = ReturnDataType
Response.Write(rJson)
Response.[End]()
End If
End Sub
Public Function
GetTagDetails() As String
Dim dt As New DataTable()
dt.Columns.Add("Tagid",
GetType(Int32))
dt.Columns.Add("TagName",
GetType(String))
dt.Columns.Add("Noofarticles",
GetType(String))
dt.Rows.Add(1, "Asp.Net",
100)
dt.Rows.Add(2, "C#.Net",
10)
dt.Rows.Add(3, "SQL
Server", 30)
dt.Rows.Add(4, "jQuery",
20)
dt.Rows.Add(6, "javascript",
15)
dt.Rows.Add(7, "XSLT",
50)
Dim strleadDetails As String = String.Empty
For i As Integer = 0 To
dt.Rows.Count - 1
Dim j As Integer = Convert.ToInt32(dt.Rows(i)(2).ToString())
If j <= 10 Then
strleadDetails += "<a
href=javascript:void(0) class=TagSize1>" + dt.Rows(i)(1) + "</a>"
ElseIf j > 10 AndAlso
j <= 20 Then
strleadDetails += "<a
href=javascript:void(0) class=TagSize2>" + dt.Rows(i)(1) + "</a>"
ElseIf j > 20 AndAlso
j <= 50 Then
strleadDetails += "<a
href=javascript:void(0) class=TagSize3>" + dt.Rows(i)(1) + "</a>"
ElseIf j > 50 AndAlso
j <= 100 Then
strleadDetails += "<a
href=javascript:void(0) class=TagSize4>" + dt.Rows(i)(1) + "</a>"
End If
Next
Return strleadDetails
End Function
End Class
|
Demo
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
|
|||
5 comments :
sir i want to know how keep submenu open when page change in jquery.
Good one
How do you create anchor link that has with parameter. e.g <a href='www.abc.com?id=xxxx' while reading datatable. id should be value of dt.Rows(i)(1). Any advice on this. Thank.
How do you create anchor link that has with parameter. e.g <a href='www.abc.com?id=xxxx' while reading datatable. id should be value of dt.Rows(i)(1). Any advice on this. Thank.
Hi Sir,
How can I stop that words which I don't want to appear. Please suggest.
Note: Only a member of this blog may post a comment.