我正在尝试实施此标记云: http://thetagcloud.codeplex.com/
...我需要将以下硬编码值替换为来自我的数据库的值?
<%= 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}"
}) %>
我创建了以下sql字符串,它以期望字符串/ int或value / key
的格式返回数据SELECT Tag, COUNT(Tag) AS Counter
FROM dbo.CtagCloud
GROUP BY Tag
HAVING (COUNT(Tag) > 3)
ORDER BY Counter DESC
答案 0 :(得分:0)
嗯,我有一个超级简短的外观,只是上面那个示例代码。我怀疑你需要传入一个数组(值对)而不是字符串。
只需遍历返回的每条记录并将其添加到数组中。然后将该数组传递给TagCloud对象。
答案 1 :(得分:0)
这是我的数据访问代码
// 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);
}