Hello,
I have an issue with a Heirarchy - Grid/Programmatic Binding.
I tried following this example as best as i can: http://demos.telerik.com/aspnet-ajax/grid/examples/programming/detailtabledatabind/defaultcs.aspx
I have a main table and three nested grids:
Main Table
- Table 1
- Table 2
- Table 3
I can expand just find from Main -> Table 1. But when i try to expand a row from table 1 to get to table 2 i keep getting an error "Object reference not set to an instance of an object". I debugged through my code and saw that it breaks down on the line that contains:
It's odd that it doesn't work because I can see the PortfoliotypeCode Column in table 1 with all the correct data, and I named everything correctly on the front end. Here is my grid front end (the table not working is named 'PortfolioTypeCode':
Here is my codebehind:
Can someone please help me? I know for a fact that the PortfolioTypeCode column is being populated because i can see it in Table 1. Why is it not able to get the datakeyvalue? It looks to me like it can't get the datakeyvalue from a detail nested table but can only read the datakeyvalues whos columns are found within the main table. Anyway around this?
Thanks!
I have an issue with a Heirarchy - Grid/Programmatic Binding.
I tried following this example as best as i can: http://demos.telerik.com/aspnet-ajax/grid/examples/programming/detailtabledatabind/defaultcs.aspx
I have a main table and three nested grids:
Main Table
- Table 1
- Table 2
- Table 3
I can expand just find from Main -> Table 1. But when i try to expand a row from table 1 to get to table 2 i keep getting an error "Object reference not set to an instance of an object". I debugged through my code and saw that it breaks down on the line that contains:
portfolioTypeCode = dataItem.GetDataKeyValue(
"PortfolioTypeCode"
).ToString();
It's odd that it doesn't work because I can see the PortfoliotypeCode Column in table 1 with all the correct data, and I named everything correctly on the front end. Here is my grid front end (the table not working is named 'PortfolioTypeCode':
<
telerik:RadGrid
ID
=
"PNLViewGrid"
runat
=
"server"
Width
=
"100%"
AutoGenerateColumns
=
"false"
AllowSorting
=
"true"
AllowPaging
=
"false"
OnNeedDataSource
=
"PNLView_NeedDataSource"
OnDetailTableDataBind
=
"PNLView_DetailTableDataBind"
>
<
MasterTableView
Width
=
"100%"
DataKeyNames
=
"PortfolioCode,PortfolioTypeCode,Strategy,StrategyId,SymbolCode,AsOfDate"
AllowMultiColumnSorting
=
"true"
>
<
DetailTables
>
<
telerik:GridTableView
DataKeyNames
=
"PortfolioCode,AsOfDate"
Name
=
"PortfolioCode"
Width
=
"100%"
>
<
DetailTables
>
<
telerik:GridTableView
DataKeyNames
=
"PortfolioCode,PortfolioTypeCode,AsOfDate"
Name
=
"PortfolioTypeCode"
Width
=
"100%"
>
<
DetailTables
>
<
telerik:GridTableView
DataKeyNames
=
"PortfolioCode,PortfolioTypeCode,StrategyId,AsOfDate"
Name
=
"Strategy"
Width
=
"100%"
>
<
Columns
>
<
telerik:GridBoundColumn
SortExpression
=
"SymbolCode"
HeaderText
=
"Symbol Code"
HeaderButtonType
=
"TextButton"
DataField
=
"SymbolCode"
/>
<
telerik:GridBoundColumn
SortExpression
=
"DailyPNL"
HeaderText
=
"Total Daily PNL"
HeaderButtonType
=
"TextButton"
DataField
=
"DailyPNL"
/>
<
telerik:GridBoundColumn
SortExpression
=
"MTDPNL"
HeaderText
=
"Total Montly PNL"
HeaderButtonType
=
"TextButton"
DataField
=
"MTDPNL"
/>
<
telerik:GridBoundColumn
SortExpression
=
"YTDPNL"
HeaderText
=
"Total Yearly PNL"
HeaderButtonType
=
"TextButton"
DataField
=
"YTDPNL"
/>
<
telerik:GridBoundColumn
SortExpression
=
"BaseMktValue"
HeaderText
=
"Total Base Market Value"
HeaderButtonType
=
"TextButton"
DataField
=
"BaseMktValue"
/>
<
telerik:GridDateTimeColumn
SortExpression
=
"AsOfDate"
HeaderText
=
"As Of Date"
HeaderButtonType
=
"TextButton"
DataField
=
"AsOfDate"
Visible
=
"false"
/>
</
Columns
>
</
telerik:GridTableView
>
</
DetailTables
>
<
Columns
>
<
telerik:GridNumericColumn
SortExpression
=
"StrategyId"
HeaderText
=
"StrategyId"
HeaderButtonType
=
"TextButton"
DataField
=
"StrategyId"
Visible
=
"false"
/>
<
telerik:GridBoundColumn
SortExpression
=
"Strategy"
HeaderText
=
"Strategy"
HeaderButtonType
=
"TextButton"
DataField
=
"Strategy"
/>
<
telerik:GridBoundColumn
SortExpression
=
"DailyPNL"
HeaderText
=
"Total Daily PNL"
HeaderButtonType
=
"TextButton"
DataField
=
"DailyPNL"
/>
<
telerik:GridBoundColumn
SortExpression
=
"MTDPNL"
HeaderText
=
"Total Montly PNL"
HeaderButtonType
=
"TextButton"
DataField
=
"MTDPNL"
/>
<
telerik:GridBoundColumn
SortExpression
=
"YTDPNL"
HeaderText
=
"Total Yearly PNL"
HeaderButtonType
=
"TextButton"
DataField
=
"YTDPNL"
/>
<
telerik:GridBoundColumn
SortExpression
=
"BaseMktValue"
HeaderText
=
"Total Base Market Value"
HeaderButtonType
=
"TextButton"
DataField
=
"BaseMktValue"
/>
<
telerik:GridDateTimeColumn
SortExpression
=
"AsOfDate"
HeaderText
=
"As Of Date"
HeaderButtonType
=
"TextButton"
DataField
=
"AsOfDate"
Visible
=
"false"
/>
</
Columns
>
</
telerik:GridTableView
>
</
DetailTables
>
<
Columns
>
<
telerik:GridBoundColumn
SortExpression
=
"PortfolioTypeCode"
HeaderText
=
"Portfolio Type Code"
HeaderButtonType
=
"TextButton"
DataField
=
"PortfolioTypeCode"
/>
<
telerik:GridBoundColumn
SortExpression
=
"DailyPNL"
HeaderText
=
"Total Daily PNL"
HeaderButtonType
=
"TextButton"
DataField
=
"DailyPNL"
/>
<
telerik:GridBoundColumn
SortExpression
=
"MTDPNL"
HeaderText
=
"Total Montly PNL"
HeaderButtonType
=
"TextButton"
DataField
=
"MTDPNL"
/>
<
telerik:GridBoundColumn
SortExpression
=
"YTDPNL"
HeaderText
=
"Total Yearly PNL"
HeaderButtonType
=
"TextButton"
DataField
=
"YTDPNL"
/>
<
telerik:GridBoundColumn
SortExpression
=
"BaseMktValue"
HeaderText
=
"Total Base Market Value"
HeaderButtonType
=
"TextButton"
DataField
=
"BaseMktValue"
/>
<
telerik:GridDateTimeColumn
SortExpression
=
"AsOfDate"
HeaderText
=
"As Of Date"
HeaderButtonType
=
"TextButton"
DataField
=
"AsOfDate"
Visible
=
"false"
/>
</
Columns
>
</
telerik:GridTableView
>
</
DetailTables
>
<
Columns
>
<
telerik:GridBoundColumn
SortExpression
=
"PortfolioCode"
HeaderText
=
"Portfolio Code"
HeaderButtonType
=
"TextButton"
DataField
=
"PortfolioCode"
/>
<
telerik:GridBoundColumn
SortExpression
=
"DailyPNL"
HeaderText
=
"Total Daily PNL"
HeaderButtonType
=
"TextButton"
DataField
=
"DailyPNL"
/>
<
telerik:GridBoundColumn
SortExpression
=
"MTDPNL"
HeaderText
=
"Total Montly PNL"
HeaderButtonType
=
"TextButton"
DataField
=
"MTDPNL"
/>
<
telerik:GridBoundColumn
SortExpression
=
"YTDPNL"
HeaderText
=
"Total Yearly PNL"
HeaderButtonType
=
"TextButton"
DataField
=
"YTDPNL"
/>
<
telerik:GridBoundColumn
SortExpression
=
"BaseMktValue"
HeaderText
=
"Total Base Market Value"
HeaderButtonType
=
"TextButton"
DataField
=
"BaseMktValue"
/>
<
telerik:GridDateTimeColumn
SortExpression
=
"AsOfDate"
HeaderText
=
"As Of Date"
HeaderButtonType
=
"TextButton"
DataField
=
"AsOfDate"
Visible
=
"false"
/>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
Here is my codebehind:
protected
void
PNLView_DetailTableDataBind(
object
sender, GridDetailTableDataBindEventArgs e)
{
GridDataItem dataItem = (GridDataItem) e.DetailTableView.ParentItem;
pnlVO item = (pnlVO) dataItem.DataItem;
string
portfolioCode =
""
;
string
portfolioTypeCode =
""
;
string
strategy =
""
;
int
strategyId = 0;
string
date =
""
;
switch
(e.DetailTableView.Name)
{
case
"PortfolioCode"
:
portfolioCode = dataItem.GetDataKeyValue(
"PortfolioCode"
).ToString();
date = dataItem.GetDataKeyValue(
"AsOfDate"
).ToString();
e.DetailTableView.DataSource = ViewUtil.Instance.GetByPortfolioTypeCode(portfolioCode, date);
break
;
case
"PortfolioTypeCode"
:
ERROR HERE ===>
portfolioTypeCode = dataItem.GetDataKeyValue(
"PortfolioTypeCode"
).ToString();
portfolioCode = dataItem.GetDataKeyValue(
"PortfolioCode"
).ToString();
date = dataItem.GetDataKeyValue(
"AsOfDate"
).ToString();
e.DetailTableView.DataSource = ViewUtil.Instance.GetByStrategy(portfolioTypeCode, portfolioCode, date);
break
;
case
"Strategy"
:
portfolioTypeCode = dataItem.GetDataKeyValue(
"PortfolioTypeCode"
).ToString();
portfolioCode = dataItem.GetDataKeyValue(
"PortfolioCode"
).ToString();
strategyId = Convert.ToInt32(dataItem.GetDataKeyValue(
"StrategyId"
).ToString());
date = dataItem.GetDataKeyValue(
"AsOfDate"
).ToString();
e.DetailTableView.DataSource = ViewUtil.Instance.GetBySymbolCode(portfolioTypeCode, portfolioCode, strategyId, date);
break
;
}
}
Can someone please help me? I know for a fact that the PortfolioTypeCode column is being populated because i can see it in Table 1. Why is it not able to get the datakeyvalue? It looks to me like it can't get the datakeyvalue from a detail nested table but can only read the datakeyvalues whos columns are found within the main table. Anyway around this?
Thanks!