Contents
Licensing
Installation and deployment
RadControls for ASP.NET AJAX Fundamentals
RadControls
RadAjax
RadAsyncUpload
RadBarcode
RadButton
RadCalendar
RadCaptcha
RadChart
RadColorPicker
RadComboBox
RadDataPager
RadDock
RadEditor
RadFileExplorer
RadFilter
RadFormDecorator
RadGrid
RadHtmlChart
RadImageEditor
RadInput
RadListBox
RadListView
RadMenu
RadNotification
RadODataDataSource
RadOrgChart
RadPanelBar
RadRating
RadRibbonBar
RadRotator
RadScheduler
RadScriptManager
RadSitemap
RadSlider
RadSocialShare
RadSpell
RadSplitter
RadStylesheetManager
RadTabStrip
RadTagCloud
RadToolBar
RadToolTip
RadTreeList
RadTreeView
RadUpload
RadWindow
RadXmlHttpPanel
Visual Studio Extensions
Integrating RadControls in ASPNET MVC
Integrating RadControls in DNN
Integrating RadControls in Mono
Integrating RadControls in SharePoint
API Reference
For More Help
|
|
        RadControls for ASP.NET AJAX RadToolBar can be bound to DataSet, DataTable, and DataView.
Creating the data table in code
The following example illustrates how to bind to a DataTable that is created in code. The same type of logic can easily be applied to a DataView instead:
-
Create a function that dynamically creates the data source (in this case, a DataTable):
CopyC# private DataTable CreateTestTable()
{
DataTable table = new DataTable();
table.Columns.Add( "Text" );
table.Columns.Add( "Value" );
table.Columns.Add( "Tooltip" );
table.Rows.Add( new string[] { "button1", "1", "tooltip1" });
table.Rows.Add(new string[] { "button2", "2", "tooltip2" });
table.Rows.Add(new string[] { "button3", "3", "tooltip3" });
return table;
} CopyVB.NET Private Function CreateTestTable() As DataTable
Dim table As New DataTable()
table.Columns.Add("Text")
table.Columns.Add("Value")
table.Columns.Add("Tooltip")
table.Rows.Add(New String() {"button1", "1", "tooltip1"})
table.Rows.Add(New String() {"button2", "2", "tooltip2"})
table.Rows.Add(New String() {"button3", "3", "tooltip3"})
Return table
End Function -
Set the DataSource property of the toolbar to the DataTable. At the same time, use the RadToolBar properties to specify the fields to use for the Text and Value properties of buttons. Finally, call the DataBind method to bind the toolbar:
CopyC# protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
RadToolBar1.DataSource = CreateTestTable();
RadToolBar1.DataTextField = "Text";
RadToolBar1.DataValueField = "Value";
RadToolBar1.DataBind();
}
} CopyVB.NET Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not IsPostBack Then
RadToolBar1.DataSource = CreateTestTable()
RadToolBar1.DataTextField = "Text"
RadToolBar1.DataValueField = "Value"
RadToolBar1.DataBind()
End If
End Sub -
Create a ButtonDataBound event handler to set additional properties on the buttons:
CopyC# protected void RadToolBar1_ButtonDataBound(object sender, RadToolBarButtonEventArgs e)
{
DataRowView row = (DataRowView)e.Button.DataItem;
e.Button.ToolTip = row["Tooltip"].ToString();
} CopyVB.NET Protected Sub RadToolBar1_ItemDataBound(ByVal sender As Object, ByVal e As RadToolBarButtonEventArgs) Handles RadToolBar1.ItemDataBound
Dim row As DataRowView = CType(e.Button.DataItem, DataRowView)
e.Button.ToolTip = row("Tooltip").ToString()
End Sub
Fetching the data from a separate database
You can use a DataSet when the data comes from a separate database. Just use a data adapter component to assign the data from the database to a DataSet:
Note |
|---|
When binding to a DataSet component, you can set the DataMember property to identify the DataTable within the DataSet to which the toolbar should be bound.
|
CopyC# protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM Table1","Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+ Server.MapPath("~/App_Data/db1.mdb" ));
DataSet table = new DataSet();
adapter.Fill(table);
RadToolBar1.DataSource = table;
RadToolBar1.DataTextField = "Text";
RadToolBar1.DataNavigateUrlField = "Value";
RadToolBar1.DataBind();
}
} CopyVB.NET Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Dim adapter As New OleDbDataAdapter("SELECT * FROM Table1", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("~/App_Data/db1.mdb"))
Dim table As New DataSet()
adapter.Fill(table)
RadToolBar1.DataSource = table
RadToolBar1.DataTextField = "Text"
RadToolBar1.DataNavigateUrlField = "Value"
RadToolBar1.DataBind()
End If
End Sub
See Also
|