Hello,
I've been trying the Rad Componets for ASP.net and a small issue came up.
I was trying to create a Self-referencing hierarchy grid programmatically on the Page_Init Event.
While I have been successful in creating the grid in the designer view, when I set up it's structure in the Page_Init the hierarchy doesn't seem to be working (ie I get all the records and columns to show normally but they don't have any children).
Is it possible to give me a few pointers on what I need to create the Self-referencing structure on the grid?
PS:My code looks like:
| <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="SelfHierarchyRadGrid._Default" %> |
| <%@ Register assembly="Telerik.Web.UI, Version=2008.3.1105.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4" 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></title> |
| </head> |
| <body> |
| <form id="form1" runat="server"> |
| <telerik:RadScriptManager runat="server"> |
| </telerik:RadScriptManager> |
| <div> |
| <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" GridLines="None"> |
| </telerik:RadGrid> |
| <asp:SqlDataSource ID="SqlDataSource1" runat="server" |
| ConnectionString="<%$ ConnectionStrings:TestDBConnectionString %>" |
| SelectCommand="SELECT [aa], [parentaa], [Text] FROM [HierarchyTest]"> |
| </asp:SqlDataSource> |
| </div> |
| </form> |
| </body> |
| </html> |
| protected void Page_Init(object sender, EventArgs e) |
| { |
| if (!IsPostBack) |
| { |
| InitGrid(); |
| } |
| } |
| private void DefineStructure() |
| { |
| RadGrid1.DataSourceID = "SqlDataSource1"; |
| RadGrid1.MasterTableView.HierarchyDefaultExpanded = true; |
| RadGrid1.MasterTableView.HierarchyLoadMode = GridChildLoadMode.Client; |
| RadGrid1.MasterTableView.AllowSorting = true; |
| string[] dkn={"aa", "parentaa"}; |
| RadGrid1.MasterTableView.DataKeyNames = new string[] { "aa", "parentaa" }; |
| RadGrid1.MasterTableView.SelfHierarchySettings.ParentKeyName = "parentaa"; |
| RadGrid1.MasterTableView.SelfHierarchySettings.KeyName = "aa"; |
| RadGrid1.ClientSettings.AllowExpandCollapse = true; |
| RadGrid1.AutoGenerateColumns = false; |
| RadGrid1.ClientSettings.Selecting.AllowRowSelect = true; |
| //Create Columns |
| GridBoundColumn boundcolumn = new GridBoundColumn(); |
| boundcolumn.datafield="aa"; |
| RadGrid1.MasterTableView.Add(boundcolumn); |
| boundcolumn.UniqueName = "aa"; |
| boundcolumn.Visible = true; |
| boundcolumn.HeaderText = "aa"; |
| //... Rest of the columns ... |
| } |