

| using System; |
| using System.Collections.Generic; |
| using System.Data; |
| using System.Web.UI; |
| using System.Web.UI.WebControls; |
| using Telerik.WebControls; |
| namespace GridTest1.Hierarchy |
| { |
| public partial class HierarchyComplex : Page |
| { |
| private RadGrid RadGrid1; |
| private List<DataItem> data; |
| protected override void OnInit(EventArgs e) |
| { |
| RadGrid1 = new RadGrid(); |
| SetupGrid(); |
| SetupGridColumns(); |
| form1.Controls.Add(RadGrid1); |
| } |
| protected void Page_Load(object sender, EventArgs e) |
| { |
| if (!IsPostBack) |
| { |
| RadGrid1.DataSource = MakeDataSet(); |
| } |
| } |
| private void SetupGrid() |
| { |
| RadGrid1.EnableViewState = true; |
| RadGrid1.MasterTableView.EnableColumnsViewState = false; |
| RadGrid1.PageSize = 30; |
| RadGrid1.AllowPaging = true; |
| RadGrid1.AllowSorting = true; |
| RadGrid1.AutoGenerateColumns = false; |
| RadGrid1.ID = "Parent"; |
| RadGrid1.MasterTableView.Name = "Table1"; |
| RadGrid1.MasterTableView.ID = "Table1"; |
| RadGrid1.PagerStyle.AlwaysVisible = true; |
| RadGrid1.PagerStyle.Mode = GridPagerMode.NextPrevNumericAndAdvanced; |
| RadGrid1.PagerStyle.Position = GridPagerPosition.TopAndBottom; |
| //RadGrid1.ItemDataBound += BindTelericGridRow; |
| RadGrid1.DetailTableDataBind += grid_DetailTableDataBind; |
| RadGrid1.NeedDataSource += grid_NeedDataSource; |
| } |
| private void SetupGridColumns() |
| { |
| MakeData(); |
| AddTemplateColumn(RadGrid1.MasterTableView, "Column1"); |
| GridTableView childView = new GridTableView(RadGrid1, true); |
| RadGrid1.MasterTableView.DataKeyNames = new string[] { "Column1" }; |
| childView.Columns.Clear(); |
| AddTemplateColumn(childView, "Column1"); |
| AddTemplateColumn(childView, "Column2"); |
| AddTemplateColumn(childView, "RowNumber").Visible = false; |
| childView.Name = "Table2"; |
| childView.AllowPaging = false; |
| childView.AllowFilteringByColumn = false; |
| childView.EnableColumnsViewState = false; |
| childView.DataMember = "Table2"; |
| childView.DataKeyNames = new string[] { "Column1" }; |
| GridRelationFields rel = new GridRelationFields(); |
| rel.DetailKeyField = "Column1"; |
| rel.MasterKeyField = "Column1"; |
| childView.ParentTableRelation.Add(rel); |
| RadGrid1.MasterTableView.DetailTables.Clear(); |
| RadGrid1.MasterTableView.DetailTables.Add(childView); |
| } |
| void grid_NeedDataSource(object source, GridNeedDataSourceEventArgs e) |
| { |
| RadGrid grid = source as RadGrid; |
| if (!e.IsFromDetailTable) |
| grid.DataSource = MakeDataSet(); |
| } |
| private GridTemplateColumn AddTemplateColumn(GridTableView view, string columnName) |
| { |
| GridTemplateColumn template = new GridTemplateColumn(); |
| ColumnTemplate cTemplate = new ColumnTemplate(columnName, data); |
| template.ItemTemplate = cTemplate; |
| template.HeaderText = columnName; |
| template.UniqueName = columnName; |
| template.DataField = columnName; |
| template.DataType = typeof(string); |
| view.Columns.Add(template); |
| return template; |
| } |
| private void grid_DetailTableDataBind(object source, GridDetailTableDataBindEventArgs e) |
| { |
| DataSet data = MakeDataSet(); |
| DataTable table = data.Tables[e.DetailTableView.DataMember]; |
| e.DetailTableView.DataSource = table; |
| } |
| public List<DataItem> MakeData() |
| { |
| data = new List<DataItem>(); |
| int parentCount = 5; |
| int childCount = 5; |
| for (int i = 0; i < parentCount; ++i) |
| { |
| for (int j = 0; j < childCount; j++) |
| { |
| DataItem item = new DataItem(i, i * parentCount + j, (j % 3) + 1); |
| data.Add(item); |
| } |
| } |
| return data; |
| } |
| private DataSet MakeDataSet() |
| { |
| DataSet dataSet = new DataSet("DataSet"); |
| DataTable table = new DataTable("Table1"); |
| table.Columns.Add(new DataColumn("Column1", typeof(string))); |
| dataSet.Tables.Add(table); |
| MakeData(); |
| int parentId = -1; |
| foreach (DataItem item in data) |
| { |
| if (item.ParentId != parentId) |
| { |
| DataRow row = table.NewRow(); |
| row["Column1"] = item.ParentId; |
| table.Rows.Add(row); |
| parentId = item.ParentId; |
| } |
| } |
| table = new DataTable("Table2"); |
| table.Columns.Add(new DataColumn("Column1", typeof(string))); |
| table.Columns.Add(new DataColumn("Column2", typeof(string))); |
| table.Columns.Add(new DataColumn("RowNumber", typeof(int))); |
| dataSet.Tables.Add(table); |
| int rowCount = 0; |
| foreach (DataItem item in data) |
| { |
| DataRow row = table.NewRow(); |
| row["Column1"] = item.ParentId; |
| row["Column2"] = item.Id; |
| row["RowNumber"] = rowCount++; |
| table.Rows.Add(row); |
| } |
| return dataSet; |
| } |
| public class ColumnTemplate : ITemplate |
| { |
| private readonly string columnName; |
| private readonly List<DataItem> dataSet; |
| public ColumnTemplate(string columnName, List<DataItem> dataSet) |
| { |
| this.columnName = columnName; |
| this.dataSet = dataSet; |
| } |
| #region ITemplate Members |
| public void InstantiateIn(Control container) |
| { |
| ColumnControl column = new ColumnControl(columnName, dataSet); |
| column.ID = "Column" + columnName; |
| container.Controls.Add(column); |
| } |
| #endregion |
| } |
| public class DataItem |
| { |
| private readonly int parentId; |
| private readonly int id; |
| private readonly int labelCount; |
| public DataItem(int parentId, int id, int labelCount) |
| { |
| this.parentId = parentId; |
| this.id = id; |
| this.labelCount = labelCount; |
| } |
| public int LabelCount |
| { |
| get { return labelCount; } |
| } |
| public int Id |
| { |
| get { return id; } |
| } |
| public int ParentId |
| { |
| get { return parentId; } |
| } |
| public List<Label> Labels |
| { |
| get |
| { |
| List<Label> labels = new List<Label>(); |
| for (int i = 0; i < labelCount; ++i) |
| { |
| Label l = new Label(); |
| l.Text = i.ToString(); |
| labels.Add(l); |
| } |
| return labels; |
| } |
| } |
| } |
| public class ColumnControl : Control |
| { |
| private DataItem data; |
| private string columnName; |
| private string tableName; |
| private readonly List<DataItem> dataSet; |
| public ColumnControl(string columnName, List<DataItem> dataSet) |
| { |
| this.columnName = columnName; |
| this.dataSet = dataSet; |
| DataBinding += ColumnControl_DataBinding; |
| } |
| void ColumnControl_DataBinding(object sender, EventArgs e) |
| { |
| GridDataItem gridData = (GridDataItem)Parent.Parent; |
| tableName = gridData.OwnerTableView.Name; |
| DataRowView dataRow = (DataRowView)(gridData).DataItem; |
| if (tableName == "Table1") |
| { |
| string item = dataRow[columnName].ToString(); |
| HyperLink l = (HyperLink)FindControl(string.Format("{0}Label", columnName)); |
| l.Text = item; |
| l.NavigateUrl = "~"; |
| } |
| if (tableName == "Table2") |
| { |
| int rowNumber = (int)dataRow["RowNumber"]; |
| data = dataSet[rowNumber]; |
| } |
| } |
| protected override void CreateChildControls() |
| { |
| //if (tableName == "Table1") |
| { |
| HyperLink l = new HyperLink(); |
| l.ID = string.Format("{0}Label", columnName); |
| Controls.Add(l); |
| } |
| if (tableName == "Table2") |
| { |
| foreach (Label c in data.Labels) |
| Controls.Add(c); |
| } |
| } |
| } |
| } |
| } |
| <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication4._Default" %> |
| <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> |
| <!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>Untitled Page</title> |
| </head> |
| <body> |
| <form id="form1" runat="server"> |
| <telerik:RadScriptManager runat="server"> |
| </telerik:RadScriptManager> |
| <telerik:RadEditor ID="RadEditor1" runat="server"> |
| <Content> |
| </Content> |
| </telerik:RadEditor> |
| </form> |
| </body> |
| </html> |
| using System; |
| using Telerik.Web.UI; |
| namespace WebApplication4 |
| { |
| public partial class _Default : System.Web.UI.Page |
| { |
| protected void Page_Load(object sender, EventArgs e) |
| { |
| RadEditor1.Language = "en-US"; |
| RadEditor1.EditModes = EditModes.Design | EditModes.Html; |
| RadEditor1.SpellCheckSettings.AllowAddCustom = false; |
| RadEditor1.SpellCheckSettings.SpellCheckProvider = SpellCheckProvider.EditDistanceProvider; |
| RadEditor1.SpellCheckSettings.EditDistance = 1; |
| RadEditor1.SpellCheckSettings.DictionaryLanguage = "en-US"; |
| RadEditor1.Skin = "Vista"; |
| RadEditor1.Content = @"After having talked a bit with these nice people we learned that we |
| learned that we were headed for the same destination, they were in fact |
| also on their other way to Italy. It turned out that we actually had |
| some things in common, all the four of us were interested in ancient |
| history and wished to see Vesuvius and Pompeii.<br /> |
| <br /> |
| <br /> |
| <a href=""#"">test</a> |
| <table> |
| <tbody> |
| <tr> |
| <td>test</td> |
| </tr> |
| </tbody> |
| </table> |
| <br /> |
| <img /> |
| "; |
| } |
| } |
| } |
| <html> |
| <head> |
| <title>Value cannot be null.<br> |
| Parameter name: InString</title> |
| <style> |
| body |
| { |
| font-family: "Verdana"; |
| font-weight: normal; |
| font-size: .7em; |
| color: black; |
| } |
| p |
| { |
| font-family: "Verdana"; |
| font-weight: normal; |
| color: black; |
| margin-top: -5px; |
| } |
| b |
| { |
| font-family: "Verdana"; |
| font-weight: bold; |
| color: black; |
| margin-top: -5px; |
| } |
| H1 |
| { |
| font-family: "Verdana"; |
| font-weight: normal; |
| font-size: 18pt; |
| color: red; |
| } |
| H2 |
| { |
| font-family: "Verdana"; |
| font-weight: normal; |
| font-size: 14pt; |
| color: maroon; |
| } |
| pre |
| { |
| font-family: "Lucida Console"; |
| font-size: .9em; |
| } |
| .marker |
| { |
| font-weight: bold; |
| color: black; |
| text-decoration: none; |
| } |
| .version |
| { |
| color: gray; |
| } |
| .error |
| { |
| margin-bottom: 10px; |
| } |
| .expandable |
| { |
| text-decoration: underline; |
| font-weight: bold; |
| color: navy; |
| cursor: hand; |
| } |
| </style> |
| </head> |
| <body bgcolor="white"> |
| <span> |
| <h1> |
| Server Error in '/' Application.<hr width="100%" size="1" color="silver"> |
| </h1> |
| <h2> |
| <i>Value cannot be null.<br> |
| Parameter name: InString</i> |
| </h2> |
| </span><font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif "><b>Description: |
| </b>An unhandled exception occurred during the execution of the current web request. |
| Please review the stack trace for more information about the error and where it |
| originated in the code. |
| <br> |
| <br> |
| <b>Exception Details: </b>System.ArgumentNullException: Value cannot be null.<br> |
| Parameter name: InString<br> |
| <br> |
| <b>Source Error:</b> |
| <br> |
| <br> |
| <table width="100%" bgcolor="#ffffcc"> |
| <tr> |
| <td> |
| <code>An unhandled exception was generated during the execution of the current web request. |
| Information regarding the origin and location of the exception can be identified |
| using the exception stack trace below.</code> |
| </td> |
| </tr> |
| </table> |
| <br> |
| <b>Stack Trace:</b> |
| <br> |
| <br> |
| <table width="100%" bgcolor="#ffffcc"> |
| <tr> |
| <td> |
| <code> |
| <pre> |
| [ArgumentNullException: Value cannot be null. |
| Parameter name: InString] |
| System.Convert.FromBase64String(String s) +0 |
| Telerik.Web.Dialogs.DialogParametersSerializer.Deserialize(String serialized) +169 |
| Telerik.Web.UI.DialogParameters.Deserialize(String source) +6 |
| Telerik.Web.UI.SpellCheckHandler.ProcessRequest(HttpContext context) +225 |
| System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +358 |
| System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) |
| +64 |
| </pre> |
| </code> |
| </td> |
| </tr> |
| </table> |
| <br> |
| <hr width="100%" size="1" color="silver"> |
| <b>Version Information:</b> Microsoft .NET Framework Version:2.0.50727.1433; |
| ASP.NET Version:2.0.50727.1433 </font> |
| </body> |
| </html> |
| <!-- |
| [ArgumentNullException]: Value cannot be null. |
| Parameter name: InString |
| at System.Convert.FromBase64String(String s) |
| at Telerik.Web.Dialogs.DialogParametersSerializer.Deserialize(String serialized) |
| at Telerik.Web.UI.DialogParameters.Deserialize(String source) |
| at Telerik.Web.UI.SpellCheckHandler.ProcessRequest(HttpContext context) |
| at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute |
| () |
| at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) |
| --> |
<telerik:RadGrid ID="rgItems" runat="server" GridLines="None" Skin="WebBlue" OnNeedDataSource="rgItems_NeedDataSource" OnRowDrop="rgItems_RowDrop" Width="460px" Height="585px">
<ClientSettings allowrowsdragdrop=True AllowColumnsReorder="True" ReorderColumnsOnClient="True">
<Selecting AllowRowSelect=True />
<ClientEvents OnRowDropping="onRowDropping"/>
<Scrolling AllowScroll="True" UseStaticHeaders="True" />
</ClientSettings>
<MasterTableView DataKeyNames="nbrItemID" TableLayout="Fixed" AutoGenerateColumns="False">
<Columns>
<telerik:GridBoundColumn UniqueName="1" DataField="txtImageHTML" >
<HeaderStyle Width="60px" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="2" DataField="txtDescriptionHTML" HeaderText="<center>New Items</center>" >
<HeaderStyle Width="220px" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="3" DataField="txtCategoryHTML" />
</Columns>
<RowIndicatorColumn Visible="False">
<HeaderStyle Width="20px" />
</RowIndicatorColumn>
<ExpandCollapseColumn Resizable="False" Visible="False">
<HeaderStyle Width="20px" />
</ExpandCollapseColumn>
<EditFormSettings>
<PopUpSettings ScrollBars="None" />
</EditFormSettings>
</MasterTableView>
</telerik:RadGrid>
Any help is greatly apreciated!