I´m using 2008.1.415.35 version of RadControls. Is it possible to do a self-reference hierarchy on a RadGrid using ArrayList datasource ? I followed some examples and I think everything is right, however the datasource data is not presented. Paging presents available data correctly, but grid table is empty. Here is my grid definition:
<telerik:RadGrid ID="Grid" runat="server" AllowSorting="True" Skin="Office2007" AllowPaging="True" AllowMultiRowSelection="True" ShowGroupPanel="True" AutoGenerateColumns="False" OnNeedDataSource="Grid_NeedDataSource" AllowFilteringByColumn="True" PageSize="20" ShowStatusBar="True" meta:resourcekey="GridResource1" OnItemDataBound="Grid_ItemDataBound" OnItemCreated="Grid_ItemCreated">
<PagerStyle Mode="NextPrevNumericAndAdvanced" />
<ExportSettings IgnorePaging="false" OpenInNewWindow="true">
<Pdf AllowAdd="false" AllowCopy="true" AllowModify="true" AllowPrinting="true" Author="Anonymous" Keywords="None" FontType="Subset" PageBottomMargin="1in" PageLeftMargin="1in" PageRightMargin="1in" PageTopMargin="1in" PageTitle="EPM Consist export document" PaperSize="Letter" Subject="EPM Consist Export" Title="EPM Consist export" />
<Excel Format="Html" />
</ExportSettings>
<ClientSettings AllowExpandCollapse="true" AllowDragToGroup="True" AllowColumnsReorder="True" ReorderColumnsOnClient="True">
<Selecting AllowRowSelect="True" />
<ClientEvents OnRowDblClick="RowDblClick" />
<ClientEvents OnRowContextMenu="RowContextMenu" />
<Resizing AllowColumnResize="True" />
<Scrolling UseStaticHeaders="True"/>
</ClientSettings>
<MasterTableView HierarchyLoadMode="Client" GroupLoadMode="Client" RetrieveAllDataFields="False" HierarchyDefaultExpanded="true" TableLayout="Auto" DataKeyNames="Item_ID,Parent_ID">
<SelfHierarchySettings ParentKeyName="Parent_ID" KeyName="Item_ID" />
<RowIndicatorColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType" Visible="False">
<HeaderStyle Width="20px" />
</RowIndicatorColumn>
<ExpandCollapseColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType" Resizable="False" Visible="False">
<HeaderStyle Width="20px" />
</ExpandCollapseColumn>
</MasterTableView>
</telerik:RadGrid>
This is Page_Load implementation. Parent_ID is compared with null because my field supports Nullable<long>.
protected void Page_Load(object sender, EventArgs e){
if (!IsPostBack){
Grid.MasterTableView.FilterExpression = "Parent_ID = null";
}
}
Thanks.
9 Answers, 1 is accepted
Basically, there is no easy way to bind the selfreferencing structure to a standard arrayList. This can be done, if the list contains objects. Thus, a sample setup may look something like:
.aspx
| <telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource" |
| AutoGenerateColumns="False" GridLines="None"> |
| <MasterTableView DataKeyNames="getParentId, getid"> |
| <SelfHierarchySettings ParentKeyName="getParentId" KeyName="getid" /> |
| <Columns> |
| <telerik:GridBoundColumn DataField="getValue" HeaderText="id" UniqueName="id" > |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="getid" HeaderText="getid" UniqueName="getid" > |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="getParentId" HeaderText="getParentId" UniqueName="getParentId" > |
| </telerik:GridBoundColumn> |
| </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><br /> |
.cs
| public partial class _Default : System.Web.UI.Page |
| { |
| protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e) |
| { |
| ArrayList list = new ArrayList(3); |
| selfReferencing obj1 = new selfReferencing(1, 0, "value1"); |
| selfReferencing obj2 = new selfReferencing(2, 1, "value2"); |
| list.Add(obj1); |
| list.Add(obj2); |
| RadGrid1.DataSource = list; |
| } |
| } |
| public class selfReferencing |
| { |
| int id; |
| int parentId; |
| string value; |
| public selfReferencing(int idValue, int parentIdValue, string valuePassed) |
| { |
| id = idValue; |
| parentId = parentIdValue; |
| value = valuePassed; |
| } |
| public string getValue |
| { |
| get |
| { |
| return this.value; |
| } |
| } |
| public int getid |
| { |
| get |
| { |
| return this.id; |
| } |
| } |
| public int getParentId |
| { |
| get |
| { |
| return this.parentId; |
| } |
| } |
| } |
I hope this information helps.
Kind regards,
Yavor
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
I'm using datatable as datasource. When I set
RadGrid1.MasterTableView.FilterExpression =
"ParentID = 0";
I'm always get error. Please, help
*aspx
<%
@ Page Language="C#" AutoEventWireup="true" CodeFile="NewSelfRef2.aspx.cs" Inherits="NewSelfRef2" %>
<%
@ 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 id="Head1" runat="server">
<title>Untitled Page</title>
</
head>
<
body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<telerik:RadGrid ID="RadGrid1" runat="server"
Skin=""
Width= "97%"
OnNeedDataSource= "RadGrid1_NeedDataSource"
GridLines="None"
ShowHeader="False">
<MasterTableView
HierarchyDefaultExpanded="True"
HierarchyLoadMode="Client"
DataKeyNames= "ParentID, ID"
Width="100%"
AutoGenerateColumns="False">
<SelfHierarchySettings
ParentKeyName="ParentID"
KeyName="ID"
/>
<Columns>
<telerik:GridBoundColumn UniqueName="Name" DataField="Name" ReadOnly="true" HeaderText="Entity Name" HeaderStyle-Width="200px"></telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="ParentID" DataField="ParentID" ItemStyle-Width="100px" HeaderStyle-Width="100px" ReadOnly="true" HeaderText="User Count"></telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="ID" DataField="ID" ReadOnly="true" HeaderText="Type" HeaderStyle-Width="194px"></telerik:GridBoundColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
</div>
</form>
</
body>
</
html>
*aspx.cs
using
System;
using
System.Collections;
using
System.Configuration;
using
System.Data;
using
System.Linq;
using
System.Web;
using
System.Web.Security;
using
System.Web.UI;
using
System.Web.UI.HtmlControls;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using
System.Xml.Linq;
using
Telerik.Web.UI;
public
partial class NewSelfRef2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
RadGrid1.MasterTableView.FilterExpression =
"ParentID = 0";
}
}
private void AddRow(DataTable table, Int32 ID, Int32 ParentID, string Name)
{
DataRow row = table.NewRow();
row[
"ID"] = ID;
row[
"ParentID"] = ParentID;
row[
"Name"] = Name;
table.Rows.Add(row);
}
protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
DataTable table = new DataTable();
table.Columns.Add(
"Name", System.Type.GetType("System.String"));
table.Columns.Add(
"ID", System.Type.GetType("System.Int32"));
table.Columns.Add(
"ParentID", System.Type.GetType("System.Int32"));
DataColumn[] PrimaryKeys = new DataColumn[1];
PrimaryKeys[0] = table.Columns[
"ID"];
table.PrimaryKey = PrimaryKeys;
AddRow(table, 1, 0,
"President");
AddRow(table, 2, 1,
"Vice President");
AddRow(table, 3, 2,
"CEO");
AddRow(table, 4, 2,
"CTO");
AddRow(table, 5, 4,
"Group PM");
AddRow(table, 6, 5,
"PM 1");
AddRow(table, 7, 5,
"PM 2");
AddRow(table, 8, 6,
"Team Leader 1");
AddRow(table, 9, 8,
"Software Engineer 1");
AddRow(table, 10, 8,
"Software Engineer 2");
AddRow(table, 11, 6,
"Test Lead 1");
AddRow(table, 12, 11,
"Tester 1");
AddRow(table, 13, 11,
"Tester 2");
AddRow(table, 14, 7,
"Team leader 2");
AddRow(table, 15, 14,
"Software Engineer 3");
AddRow(table, 16, 14,
"Software Engineer 4");
AddRow(table, 17, 7,
"Test Lead 2");
AddRow(table, 18, 17,
"Tester 3");
AddRow(table, 19, 17,
"Tester 4");
AddRow(table, 20, 17,
"Tester 5");
table.AcceptChanges();
RadGrid1.DataSource = table;
}
}
I tested the setup mentioned, and the control behaved properly.
Attached to this message, is the sample code, which I used for testing.
Let me know if I am leaving something out.
Sincerely yours,
Yavor
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
This fixed the self reference grid problem. I noticed that you use Telerik.Web.UI.dll 2008.1.407.20. Could you please advise when and where we can download that?
Thanks,
Vinhlan
You can download the latest version of Q1 2008 of RadControls for ASP.NET AJAX (2008.1.415) from your Client.net account -> My Licenses -> My Free trials or MyPurchases respectively.
Best regards,
Stephen
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
Yavor provide the solution using Telerik.Web.UI.dll 2008.1.407.20. I´m using 2008.1.415.35 version of RadControls for ASP.NET AJAX. However, this still cause the self reference grid as I described above. Please, help
Thanks,
Vinhlan
Does the problem persist, when you set EnableLinqExpressions="false" for the control?
All the best,
Yavor
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
That fixed the self grid problem.
Thanks heap,
Vinhlan