Hi,
I am trying to create a hierarchical grid as found in this demo. I am not sure that what I am trying to do is possible due to the way my data is structured. I am pulling
data from multiple Oracle tables and storing it in a single SQL Server table. This table is basically a view of the Oracle data and as such I am obviously losing any relations that existed in the original data. So I guess my question is...is it possible to create a hierarchical grid from a single database table?
Using the before referenced demo, I receive the following error:
There was a problem extracting DataKeyValues from the DataSource. Please ensure that DataKeyNames are specified correctly and all fields specified exist in the
DataSource.
I have the following fields in my SQL Server table:
proj_id, proj_short_name, wbs_id, wbs_name, task_id, task_code, task_name, short_name, proc_id, proc_name, proc_wt, complete_pct
wbs_id and proc_id represent the composite primary_key
The top level of the RadGrid should show wbs_name and short_name
The 2nd level should show task_id, task_name
The 3rd level should show proc_name, proc_wt and complete_pct
Here is my markup and code:
ASPX:
C#:
The error is being thrown on RadGrid1_PreRender.
Thanks in advance,
Josh
I am trying to create a hierarchical grid as found in this demo. I am not sure that what I am trying to do is possible due to the way my data is structured. I am pulling
data from multiple Oracle tables and storing it in a single SQL Server table. This table is basically a view of the Oracle data and as such I am obviously losing any relations that existed in the original data. So I guess my question is...is it possible to create a hierarchical grid from a single database table?
Using the before referenced demo, I receive the following error:
There was a problem extracting DataKeyValues from the DataSource. Please ensure that DataKeyNames are specified correctly and all fields specified exist in the
DataSource.
I have the following fields in my SQL Server table:
proj_id, proj_short_name, wbs_id, wbs_name, task_id, task_code, task_name, short_name, proc_id, proc_name, proc_wt, complete_pct
wbs_id and proc_id represent the composite primary_key
The top level of the RadGrid should show wbs_name and short_name
The 2nd level should show task_id, task_name
The 3rd level should show proc_name, proc_wt and complete_pct
Here is my markup and code:
ASPX:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="practiceTemplate.aspx.cs" Inherits="ProgramStatusManagementSystemWebApp.primavera.practiceTemplate" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!DOCTYPE html>
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
head
runat
=
"server"
>
<
title
></
title
>
</
head
>
<
body
>
<
form
id
=
"form1"
runat
=
"server"
>
<
div
>
<
telerik:RadScriptManager
ID
=
"RadScriptManager1"
runat
=
"server"
></
telerik:RadScriptManager
>
<
telerik:RadSkinManager
ID
=
"RadSkinManager1"
runat
=
"server"
ShowChooser
=
"true"
></
telerik:RadSkinManager
>
<
telerik:RadAjaxManager
ID
=
"RadAjaxManager1"
runat
=
"server"
>
<
AjaxSettings
>
<
telerik:AjaxSetting
AjaxControlID
=
"RadGrid1"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadGrid1"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
</
AjaxSettings
>
</
telerik:RadAjaxManager
>
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
ShowStatusBar
=
"true"
AutoGenerateColumns
=
"False"
PageSize
=
"7"
AllowSorting
=
"True"
AllowMultiRowSelection
=
"False"
AllowPaging
=
"True"
OnDetailTableDataBind
=
"RadGrid1_DetailTableDataBind"
OnNeedDataSource
=
"RadGrid1_NeedDataSource"
OnPreRender
=
"RadGrid1_PreRender"
>
<
PagerStyle
Mode
=
"NumericPages"
></
PagerStyle
>
<
MasterTableView
DataKeyNames
=
"wbs_id"
AllowMultiColumnSorting
=
"True"
>
<
DetailTables
>
<
telerik:GridTableView
DataKeyNames
=
"wbs_id"
Name
=
"Activities"
Width
=
"100%"
>
<
DetailTables
>
<
telerik:GridTableView
DataKeyNames
=
"task_id"
Name
=
"StepDetails"
Width
=
"100%"
>
<
Columns
>
<
telerik:GridBoundColumn
SortExpression
=
"proc_id"
HeaderText
=
"Step ID"
HeaderButtonType
=
"TextButton"
DataField
=
"proc_id"
UniqueName
=
"proc_id"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
SortExpression
=
"proc_name"
HeaderText
=
"Step Name"
HeaderButtonType
=
"TextButton"
DataField
=
"proc_name"
UniqueName
=
"proc_name"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
SortExpression
=
"proc_wt"
HeaderText
=
"Step Weight"
HeaderButtonType
=
"TextButton"
DataField
=
"proc_wt"
UniqueName
=
"proc_wt"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
SortExpression
=
"complete_pct"
HeaderText
=
"Percent Complete"
HeaderButtonType
=
"TextButton"
DataField
=
"complete_pct"
>
</
telerik:GridBoundColumn
>
</
Columns
>
</
telerik:GridTableView
>
</
DetailTables
>
<
Columns
>
<
telerik:GridBoundColumn
SortExpression
=
"task_code"
HeaderText
=
"Activity ID"
HeaderButtonType
=
"TextButton"
DataField
=
"task_code"
UniqueName
=
"task_code"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
SortExpression
=
"task_name"
HeaderText
=
"Activity Name"
HeaderButtonType
=
"TextButton"
DataField
=
"task_name"
UniqueName
=
"task_name"
DataFormatString
=
"{0:D}"
>
</
telerik:GridBoundColumn
>
</
Columns
>
</
telerik:GridTableView
>
</
DetailTables
>
<
Columns
>
<
telerik:GridBoundColumn
SortExpression
=
"wbs_name"
HeaderText
=
"WBS Name"
HeaderButtonType
=
"TextButton"
DataField
=
"wbs_name"
UniqueName
=
"wbs_name"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
SortExpression
=
"short_name"
HeaderText
=
"CAM"
HeaderButtonType
=
"TextButton"
DataField
=
"short_name"
UniqueName
=
"short_name"
>
</
telerik:GridBoundColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
</
div
>
</
form
>
</
body
>
</
html
>
C#:
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
namespace ProgramStatusManagementSystemWebApp.primavera
{
public partial class practiceTemplate : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void RadGrid1_DetailTableDataBind(object sender, Telerik.Web.UI.GridDetailTableDataBindEventArgs e)
{
GridDataItem dataItem = (GridDataItem)e.DetailTableView.ParentItem;
switch (e.DetailTableView.Name)
{
case "Activities":
{
string wbsID = dataItem.GetDataKeyValue("wbs_id").ToString();
//string rowuid = dataItem.GetDataKeyValue("rowuid").ToString();
e.DetailTableView.DataSource = GetDataTable("SELECT task_code, task_name FROM PrimaveraStatusTemplate3 WHERE wbs_id = " + wbsID + "");
//e.DetailTableView.DataSource = GetDataTable("SELECT task_code, task_name FROM PrimaveraStatusTemplate3 WHERE rowuid = " + rowuid + "");
break;
}
case "StepDetails":
{
string taskID = dataItem.GetDataKeyValue("task_id").ToString();
e.DetailTableView.DataSource = GetDataTable("SELECT proc_name, proc_wt, complete_pct FROM PrimaveraStatusTemplate3 WHERE task_id = " + taskID + "");
break;
}
}
}
protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
if (!e.IsFromDetailTable)
{
RadGrid1.DataSource = GetDataTable("SELECT * FROM PrimaveraStatusTemplate3");
}
}
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
RadGrid1.MasterTableView.Items[0].Expanded = true;
RadGrid1.MasterTableView.Items[0].ChildItem.NestedTableViews[0].Items[0].Expanded = true;
}
}
public DataTable GetDataTable(string query)
{
String ConnString = ConfigurationManager.ConnectionStrings["PSMSystemConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(ConnString);
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand(query, conn);
DataTable myDataTable = new DataTable();
conn.Open();
try
{
adapter.Fill(myDataTable);
}
finally
{
conn.Close();
}
return myDataTable;
}
}
}
The error is being thrown on RadGrid1_PreRender.
Thanks in advance,
Josh