I have a hierarchical grid setup with a single child level. When the page loads the grid shows perfectly fine - all levels (hierarchy mode is Client) show up and everything looks great. When I use the Delete command to remove one of the child items the delete process works fine, however the Rebind method dies. It seems when the Rebind() method gets called the detail table's data source is actually being set to the parent object so upon binding it tells me the type I am trying to call a property off of (ImageName is the property) doesn't exist. Any thoughts here? It doesn't make sense that a Rebind wouldn't work, yet binding when the page loads initially works fine. Here is the code:
protected
void
grProjects_NeedDataSource(
object
sender, GridNeedDataSourceEventArgs e)
{
if
(!e.IsFromDetailTable)
{
this
.grProjects.DataSource = (from c
in
new
DataContext().Projects select c).ToArray();
}
}
protected
void
grProjects_DetailTableDataBind(
object
source, GridDetailTableDataBindEventArgs e)
{
if
(e.DetailTableView.Name ==
"Images"
)
{
GridDataItem dataItem = (GridDataItem)e.DetailTableView.ParentItem;
e.DetailTableView.DataSource = ((Project)dataItem.DataItem).ProjectItems;
}
}
<
telerik:RadGrid
runat
=
"server"
ID
=
"grProjects"
OnNeedDataSource
=
"grProjects_NeedDataSource"
Skin
=
"Windows7"
AutoGenerateColumns
=
"false"
ShowFooter
=
"false"
OnItemDataBound
=
"grProjects_ItemDataBound"
OnItemCommand
=
"grProjects_ItemCommand"
OnDetailTableDataBind
=
"grProjects_DetailTableDataBind"
>
<
MasterTableView
DataKeyNames
=
"Id"
CommandItemDisplay
=
"Top"
CommandItemStyle-Height
=
"30px"
ItemStyle-VerticalAlign
=
"Top"
AlternatingItemStyle-VerticalAlign
=
"Top"
HierarchyDefaultExpanded
=
"false"
HierarchyLoadMode
=
"Client"
>
<
CommandItemTemplate
>
<
input
type
=
"button"
class
=
"rgAdd"
onclick
=
"javascript:addItem();"
style
=
"margin-left: 10px;"
/><
a
href
=
"javascript:;"
onclick
=
"javascript:addItem();"
>Add Project</
a
>
</
CommandItemTemplate
>
<
Columns
>
<
telerik:GridTemplateColumn
ItemStyle-Width
=
"20px"
ItemStyle-Wrap
=
"false"
>
<
ItemTemplate
>
<
asp:Button
runat
=
"server"
ID
=
"cmEdit"
Text
=
"Edit"
CssClass
=
"rgEdit"
/>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridBoundColumn
HeaderText
=
"Name"
DataField
=
"Name"
ItemStyle-Width
=
"125px"
/>
<
telerik:GridBoundColumn
HeaderText
=
"Description"
DataField
=
"Description"
/>
<
telerik:GridButtonColumn
ButtonType
=
"ImageButton"
HeaderStyle-Width
=
"20px"
ItemStyle-Width
=
"20px"
CommandName
=
"Delete"
ConfirmDialogType
=
"RadWindow"
ConfirmText="Are you sure you wish to permanently remove this project?<br /><
br
/><
strong
>All images contained inside will be removed as well and this action is not reversible.</
strong
>" />
</
Columns
>
<
DetailTables
>
<
telerik:GridTableView
Name
=
"Images"
DataKeyNames
=
"Id"
CommandItemDisplay
=
"Top"
CommandItemStyle-Height
=
"30px"
ItemStyle-VerticalAlign
=
"Top"
AlternatingItemStyle-VerticalAlign
=
"Top"
Width
=
"100%"
>
<
CommandItemTemplate
>
<
asp:Button
runat
=
"server"
ID
=
"cmAddItem"
CssClass
=
"rgAdd"
style
=
"margin-left: 10px;"
/><
asp:HyperLink
runat
=
"server"
ID
=
"lkAddItem"
Text
=
"Add Image"
NavigateUrl
=
"javascript:;"
/>
</
CommandItemTemplate
>
<
Columns
>
<
telerik:GridTemplateColumn
ItemStyle-Width
=
"20px"
ItemStyle-Wrap
=
"false"
>
<
ItemTemplate
>
<
asp:Button
runat
=
"server"
ID
=
"cmEdit"
Text
=
"Edit"
CssClass
=
"rgEdit"
/>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
HeaderText
=
"Image"
ItemStyle-Width
=
"100px"
>
<
ItemTemplate
>
<
asp:Image
runat
=
"server"
ImageUrl='<%# GetImageUrl(Eval("ImageName")) %>' />
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
HeaderText
=
"Caption"
>
<
ItemTemplate
>
<%#(Eval("Caption") != null) ? Eval("Caption").ToString().Replace("\r\n", "<
br
/>") : string.Empty %>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridButtonColumn
ButtonType
=
"ImageButton"
HeaderStyle-Width
=
"20px"
ItemStyle-Width
=
"20px"
CommandName
=
"Delete"
ConfirmDialogType
=
"RadWindow"
ConfirmText="Are you sure you wish to permanently remove this item?<br /><
br
/><
strong
>This action is not reversible.</
strong
>" />
</
Columns
>
</
telerik:GridTableView
>
</
DetailTables
>
</
MasterTableView
>
</
telerik:RadGrid
>