I have a radgrid that binds an object stored in the ViewState (Case). When I click on the radgrid's "Add" button (firing the OnInsertCommand) I get the following error: 'Telerik.Web.UI.GridInsertionObject' does not contain a property with the name 'LookupValue'.' The specific control I am having problems with is the RadDropDownTree, and only when its definition contains this "SelectedValue='<%# Bind("LookupValue.Code") %>'"
I do not understand why this is happening. What is so different now that my radgrid is binding to a object that contains a subobject?? What do I need to be doing differently?
Just as an fyi, I do not get this error when the OnUpdateCommand fires. Below is my code.
<telerik:RadGrid ID="gvAllegations" runat="server"
AllowAutomaticDeletes="false"
AllowAutomaticInserts="false"
AllowAutomaticUpdates="false"
AllowFilteringByColumn="false"
AllowMultiRowEdit="false"
AllowMultiRowSelection="false"
AllowPaging="false"
AllowSorting="false"
AutoGenerateColumns="false"
OnNeedDataSource="gvAllegations_NeedDataSource"
OnInsertCommand="gvAllegations_InsertCommand"
OnUpdateCommand="gvAllegations_UpdateCommand">
<ClientSettings Selecting-AllowRowSelect="true" />
<GroupingSettings CaseSensitive="false" />
<MasterTableView
CommandItemDisplay="Top"
DataKeyNames="CaseAllegationID"
ClientDataKeyNames="CaseAllegationID">
<Columns>
<telerik:GridBoundColumn UniqueName="AllegationType" DataField="Type" HeaderText="Type" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" />
<telerik:GridBoundColumn UniqueName="AllegationCodeDescription" DataField="LookupValue.CodeDescription" HeaderText="Allegation" />
</Columns>
<CommandItemTemplate>
<div class="CommandButtonDiv">
<asp:LinkButton ID="LinkButton2" runat="server"
CssClass="CommandButton"
CommandName="InitInsert"
Visible='<%# !gvAllegations.MasterTableView.IsItemInserted && gvAllegations.EditIndexes.Count == 0 %>'>
<img src="Images/AddRecord.png"/> Add
</asp:LinkButton>
<asp:LinkButton ID="btnEditSelected" runat="server"
CssClass="CommandButton"
CommandName="EditSelected"
Visible='<%# !gvAllegations.MasterTableView.IsItemInserted && gvAllegations.EditIndexes.Count == 0 %>'>
<img src="Images/Edit.png" /> Edit
</asp:LinkButton>
<asp:LinkButton ID="LinkButton1" runat="server"
CssClass="CommandButton"
CommandName="DeleteSelected"
Visible='<%# !gvAllegations.MasterTableView.IsItemInserted && gvAllegations.EditIndexes.Count == 0 %>'>
<img src="Images/Delete.png"/> Delete
</asp:LinkButton>
<asp:LinkButton ID="LinkButton4" runat="server"
CssClass="CommandButton"
CommandName="RebindGrid"
Visible='<%# !gvAllegations.MasterTableView.IsItemInserted && gvAllegations.EditIndexes.Count == 0 %>'>
<img src="Images/Refresh.png"/> Refresh
</asp:LinkButton>
<asp:LinkButton ID="LinkButton3" runat="server"
CssClass="CommandButton"
CommandName="PerformInsert" Visible='<%# gvAllegations.MasterTableView.IsItemInserted %>'>
<img src="Images/Insert.gif"/> Save
</asp:LinkButton>
<asp:LinkButton ID="LinkButton5" runat="server"
CssClass="CommandButton"
CommandName="UpdateEdited" Visible='<%# gvAllegations.EditIndexes.Count > 0 %>'>
<img src="Images/Update.png"/> Update
</asp:LinkButton>
<asp:LinkButton ID="btnCancel" runat="server"
CssClass="CommandButton"
CommandName="CancelAll" Visible='<%# gvAllegations.MasterTableView.IsItemInserted || gvAllegations.EditIndexes.Count > 0 %>'>
<img src="Images/Cancel.png"/> Cancel
</asp:LinkButton>
</div>
</CommandItemTemplate>
<EditFormSettings EditFormType="Template">
<FormTemplate>
<table style="width: 100%">
<tr>
<td>Allegation</td>
<td>
<telerik:RadDropDownTree ID="ddtAllegation" runat="server"
AutoPostBack="False"
DataFieldId="Code"
DataFieldParentID="ParentCode"
DataValueField="Code"
DataSourceID="odsAllegationLookupValues"
DataTextField="CodeDescription"
EnableFiltering="True"
ExpandNodeOnSingleClick="True"
SelectedValue='<%# Bind("LookupValue.Code") %>'
Width="300px">
<DropDownSettings AutoWidth="Enabled" CloseDropDownOnSelection="true" />
<FilterSettings EmptyMessage="Search Allegation" Filter="Contains" Highlight="Matches" />
</telerik:RadDropDownTree>
</td>
</tr>
<tr>
<td>Major Allegation</td>
<td><telerik:RadCheckBox ID="chbMajorAllegation" runat="server"
AutoPostBack="False" Checked='<%# Bind("IsMajor") %>' /></td>
</tr>
<tr>
<td colspan="2" style="text-align: center">
<telerik:RadButton ID="btnInsert" runat="server"
CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'
Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
Width="100px" />
<telerik:RadButton ID="btnCancel" runat="server"
Text="Cancel"
CommandName="Cancel"
Width="100px" />
</td>
</tr>
</table>
</FormTemplate>
</EditFormSettings>
</MasterTableView>
</telerik:RadGrid>
[Serializable]
public class Case
{
public int ID { get; set; }
public List<Allegation> Allegations { get; set; }
}
[Serializable]
public class Allegation
{
public int CaseAllegationID { get; set; }
public bool IsMajor { get; set; }
public string Type
{
get
{
if (IsMajor)
return "Major";
else
return "Other";
}
}
public LookupValue LookupValue { get; set; }
}
[Serializable]
public class LookupValue
{
public string Code { get; set; }
public string Description { get; set; }
public string CodeDescription { get { return Code + " - " + Description; } }
public string ParentCode { get; set; }
public int DimID { get; set; }
public DateTime DimStartDate { get; set; }
public DateTime DimEndDate { get; set; }
public bool DimIsActive { get; set; }
}
protected void gvAllegations_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
gvAllegations.DataSource = ((Case)ViewState["rcaCase"]).Allegations;
}
protected void gvAllegations_InsertCommand(object sender, GridCommandEventArgs e)
{
}