New to Telerik UI for ASP.NET AJAXStart a free 30-day trial

Binding to DataTable, DataSet or DataView

RadTagCloud can be bound to a DataTable, DataSet and a DataView. This example shows binding to a DataTable object.

The declaration of the RadTagCloud object includes no DataSourceID property or <Items> section:

ASP.NET
<telerik:RadTagCloud RenderMode="Lightweight" ID="RadTagCloud1" runat="server" Width="400px">
</telerik:RadTagCloud>

In the Page_Load event handler, create and fill the DataTable object, then bind it to the tagCloud. You must call the DataBind method after setting the DataSource property.

C#
protected void Page_Load(object sender, EventArgs e)
{
	if (!Page.IsPostBack)
	{
		BindToDataTable(RadTagCloud1);
	}
}
private void BindToDataTable(RadTagCloud cloud)
{
	SqlConnection con = new SqlConnection("Data Source=LOCAL;Initial Catalog=TagCloud;Integrated Security=True");
	SqlDataAdapter adapter = new SqlDataAdapter("SELECT [Text], [Weight], [NavigateUrl] FROM [Links]", con);
	DataTable links = new DataTable();
	adapter.Fill(links);
	cloud.DataTextField = "Text";
	cloud.DataWeightField = "Weight";
	cloud.DataNavigateUrlField = "NavigateUrl";
	cloud.DataSource = links;
	cloud.DataBind();
}
Not finding the help you need?
Contact Support