I'm trying to implement this tag cloud: http://thetagcloud.codeplex.com/
...and I need the replace the hard-coded values below with those coming from my database?
<%= new TagCloud( new Dictionary<string, int> {
{"C#", 58},
{"ASP.NET", 45},
{"VB.NET", 36},
开发者_如何学运维 {"AJAX", 24},
{"LINQ", 13}
},
new TagCloudGenerationRules
{
TagToolTipFormatString = "Tag weight: {0}",
TagUrlFormatString = "search.aspx?p=1&tag={0}"
}) %>
I've created the following sql string which returns the data in the format expected string/int or value/key
SELECT Tag, COUNT(Tag) AS Counter
FROM dbo.CtagCloud
GROUP BY Tag
HAVING (COUNT(Tag) > 3)
ORDER BY Counter DESC
here's my data access code
// SQL Select Command
SqlConnection conn = new SqlConnection(connectionString);
SqlCommand mySqlSelect = new SqlCommand("SELECT TOP (100) PERCENT Tag, COUNT(Tag) AS Counter FROM dbo.CtagCloud GROUP BY Tag HAVING (COUNT(Tag) > 3) ORDER BY Counter DESC", conn);
mySqlSelect.CommandType = CommandType.Text;
SqlDataAdapter mySqlAdapter = new SqlDataAdapter(mySqlSelect);
DataSet myDataSet = new DataSet();
mySqlAdapter.Fill(myDataSet);
// create an instance for ArrayList
ArrayList myArrayList = new ArrayList();
// foreach loop to read each DataRow of DataTable stored inside the DataSet
foreach (DataRow dRow in myDataSet.Tables[0].Rows)
{
// add DataRow object to ArrayList
myArrayList.Add(dRow);
}
Hmm, I've had a super brief look, just glazing over that sample code. I suspect you need to pass in an Array (value pairs) not a string.
Just loop through each records returned and add it to an array. Then pass that array into the TagCloud object.
精彩评论