or
<telerik:RadGrid ID="CoursesGrid" runat="server" Width="920px" AutoGenerateColumns="False" PageSize="20" AllowPaging="True" CssClass="AddBorders"> <MasterTableView DataKeyNames="CourseID" EditMode="EditForms" CommandItemDisplay="Top" CommandItemSettings-AddNewRecordText="Add New Course" InsertItemDisplay="Top" InsertItemPageIndexAction="ShowItemOnCurrentPage" EnableNoRecordsTemplate="true" ShowHeader="true"> <Columns> <telerik:GridEditCommandColumn UniqueName="EditBtn" ButtonType="ImageButton" HeaderStyle-Width="60px" Resizable="false" ItemStyle-HorizontalAlign="Center"></telerik:GridEditCommandColumn> <telerik:GridBoundColumn UniqueName="CourseID" DataField="CourseID" HeaderText="Course ID" ColumnEditorID="CourseIDEditor" HeaderStyle-Width="70px" Resizable="false" ItemStyle-HorizontalAlign="Center"></telerik:GridBoundColumn> <telerik:GridBoundColumn UniqueName="CourseName" DataField="CourseName" HeaderText="Course Name" ColumnEditorID="CourseNameEditor" HeaderStyle-Width="380px" Resizable="false"></telerik:GridBoundColumn> <telerik:GridDateTimeColumn UniqueName="FromDate" DataField="FromDate" HeaderText="From" DataFormatString="{0:dd/MM/yyyy}" HeaderStyle-Width="80px" Resizable="false" ItemStyle-HorizontalAlign="Center"></telerik:GridDateTimeColumn> <telerik:GridDateTimeColumn UniqueName="ToDate" DataField="ToDate" HeaderText="To" DataFormatString="{0:dd/MM/yyyy}" HeaderStyle-Width="80px" Resizable="false" ItemStyle-HorizontalAlign="Center"></telerik:GridDateTimeColumn> <telerik:GridBoundColumn UniqueName="Venue" DataField="Venue" HeaderText="Venue" ColumnEditorID="VenueEditor" HeaderStyle-Width="80px" Resizable="false" ItemStyle-HorizontalAlign="Center"></telerik:GridBoundColumn> <telerik:GridDropDownColumn UniqueName="Category" HeaderText="Category" DataField="CatID" HeaderStyle-Width="160px" Resizable="false" ItemStyle-HorizontalAlign="Center"></telerik:GridDropDownColumn> </Columns> <NoRecordsTemplate> <div id="NoRecordWrapper">No Courses available!</div> </NoRecordsTemplate> </MasterTableView> <HeaderStyle Font-Bold="true" HorizontalAlign="Center" /> <ClientSettings EnableAlternatingItems="true"> </ClientSettings></telerik:RadGrid>Protected Sub CoursesDataBound(ByVal sender As Object, ByVal e As GridItemEventArgs) Handles CoursesGrid.ItemDataBound Try '-------------------------------------------------------- ' 1. Display (Regular) Mode '-------------------------------------------------------- If TypeOf e.Item Is GridDataItem Then ' 1.1 Get reference of current Item & its Data '---------------------------------------------------- Dim courseRec As GridDataItem = CType(e.Item, GridDataItem) Dim courseInfo As DataRowView = CType(courseRec.DataItem, DataRowView) ' 1.2 Set style of Arabic content '---------------------------------------------------- If Not IsDBNull(courseInfo("Locale")) Then courseRec("CourseName").CssClass = "arabicText" courseRec("CourseName").HorizontalAlign = HorizontalAlign.Right If Not IsDBNull(courseInfo("Venue")) Then courseRec("Venue").CssClass = "arabicText" End If End If ' 1.3 Replace Subject ID with its Description '---------------------------------------------------- Dim catID As String = courseInfo("CatID") Dim catDesc As String = CodeLibrary.CatList.Item(catID) courseRec("Category").Text = catDesc End If '-------------------------------------------------------- ' 2. Edit/Insert Mode '-------------------------------------------------------- If TypeOf e.Item Is GridEditableItem AndAlso CType(e.Item, GridEditableItem).IsInEditMode Then ' 2.1 Get reference of Edit Manager '---------------------------------------------------- Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem) Dim editMan As GridEditManager = editedItem.EditManager ' 2.2 Handle 'Category' DropDownList '---------------------------------------------------- ' 2.2.1 Get reference of respective ColumnEditor ' ................................................ Dim subjectEditor As GridDropDownListColumnEditor = CType(editMan.GetColumnEditor("Category"), GridDropDownListColumnEditor) Dim subjectsList As RadComboBox = subjectEditor.ComboBoxControl ' 2.2.2 Populate ' ................................................ subjectEditor.DataSource = CodeLibrary.CatList subjectEditor.DataTextField = "Value" subjectEditor.DataValueField = "Key" subjectEditor.DataBind() subjectsList.Items.Insert(0, New RadComboBoxItem("--- SELECT ---", "XX")) ' 2.2.3 Set Selected Value ' ................................................ subjectsList.SelectedValue = "XX" If Not e.Item.OwnerTableView.IsItemInserted Then subjectsList.SelectedValue = e.Item.DataItem("CatID") End If ' 2.2.4 Set Width ' ................................................ subjectsList.Width = Unit.Pixel(200) ' 2.3 Style 'Course Name' if Arabic '---------------------------------------------------- Dim nameEditor As GridTextBoxColumnEditor = CType(editMan.GetColumnEditor("CourseName"), GridTextBoxColumnEditor) Dim textColumn As TextBox = nameEditor.TextBoxControl If Not IsDBNull(e.Item.DataItem("Locale")) Then textColumn.CssClass = "arabicText alignRight" End If ' 2.4 Disable 'CourseID' on Edit '---------------------------------------------------- If Not TypeOf e.Item Is IGridInsertItem Then Dim idEditor As GridTextBoxColumnEditor = CType(editMan.GetColumnEditor("CourseID"), GridTextBoxColumnEditor) idEditor.TextBoxControl.Enabled = False End If End If Catch ex As Exception Dim errorMsg As String = String.Format("â–º CoursesDataBound: [{0}]", ex.Message) DisplayFeedback("page", Nothing, errorMsg) End TryEnd Sub
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title></title></head><body> <form id="form1" runat="server"> <telerik:RadScriptManager runat="server" ID="RadScriptManager1" /> <telerik:RadButton ID="btnExpand" runat="server" Text="Expand All" OnClick="btnExpand_Click"> </telerik:RadButton> <telerik:RadButton ID="btnCollapse" runat="server" Text="Collapse All" OnClick="btnCollapse_Click"> </telerik:RadButton> <br/> <telerik:RadAjaxPanel runat="server" ID="RadAjaxPanel"> <telerik:RadOrgChart ID="RadOrgChart1" runat="server" EnableCollapsing="true" Skin="Office2010Blue" /> </telerik:RadAjaxPanel> </form></body></html>protected void Page_Load(object sender, EventArgs e){ var employees = CreateEmployees(); RadOrgChart1.DataFieldID = "EmployeeID"; RadOrgChart1.DataFieldParentID = "ParentID"; RadOrgChart1.DataTextField = "Name"; //RadOrgChart1.DataImageUrlField = "ImageUrl"; RadOrgChart1.DataSource = employees; RadOrgChart1.DataBind();}private DataTable CreateEmployees(){ var employees = new DataTable(); employees.Columns.Add("EmployeeID"); employees.Columns.Add("ParentID"); employees.Columns.Add("Name"); employees.Columns.Add("ImageUrl"); employees.Rows.Add(new string[] { "1", null, "Kate", "~/Img/Northwind/Customers/LONEP.jpg" }); employees.Rows.Add(new string[] { "2", "1", "Peter", "~/Img/Northwind/Customers/SAVEA.jpg" }); employees.Rows.Add(new string[] { "21", "1", "Peter1", "~/Img/Northwind/Customers/SAVEA.jpg" }); employees.Rows.Add(new string[] { "22", "1", "Peter2", "~/Img/Northwind/Customers/SAVEA.jpg" }); employees.Rows.Add(new string[] { "23", "1", "Peter3", "~/Img/Northwind/Customers/SAVEA.jpg" }); employees.Rows.Add(new string[] { "24", "1", "Peter4", "~/Img/Northwind/Customers/SAVEA.jpg" }); employees.Rows.Add(new string[] { "25", "1", "Peter5", "~/Img/Northwind/Customers/SAVEA.jpg" }); employees.Rows.Add(new string[] { "26", "1", "Peter6", "~/Img/Northwind/Customers/SAVEA.jpg" }); employees.Rows.Add(new string[] { "27", "1", "Peter7", "~/Img/Northwind/Customers/SAVEA.jpg" }); employees.Rows.Add(new string[] { "3", "2", "Arnold", "~/Img/Northwind/Customers/LACOR.jpg" }); employees.Rows.Add(new string[] { "31", "21", "Arnold31", "~/Img/Northwind/Customers/LACOR.jpg" }); employees.Rows.Add(new string[] { "32", "21", "Arnold32", "~/Img/Northwind/Customers/LACOR.jpg" }); employees.Rows.Add(new string[] { "41", "22", "Arnold41", "~/Img/Northwind/Customers/LACOR.jpg" }); employees.Rows.Add(new string[] { "42", "22", "Arnold42", "~/Img/Northwind/Customers/LACOR.jpg" }); employees.Rows.Add(new string[] { "51", "23", "Arnold51", "~/Img/Northwind/Customers/LACOR.jpg" }); employees.Rows.Add(new string[] { "52", "23", "Arnold52", "~/Img/Northwind/Customers/LACOR.jpg" }); employees.Rows.Add(new string[] { "4", "3", "Tim", "~/Img/Northwind/Customers/GREAL.jpg" }); employees.Rows.Add(new string[] { "5", "3", "Nora", "~/Img/Northwind/Customers/TRADH.jpg" }); employees.Rows.Add(new string[] { "6", "4", "David", "~/Img/Northwind/Customers/CENTC.jpg" }); employees.Rows.Add(new string[] { "7", "2", "Mike", "~/Img/Northwind/Customers/VAFFE.jpg" }); return employees;}protected void btnCollapse_Click(object sender, EventArgs e){ RadOrgChart1.CollapseAllNodes();}protected void btnExpand_Click(object sender, EventArgs e){ RadOrgChart1.ExpandAllNodes();}