Hello,
I try to use a hierarchical grid using entity-data. Viewing, updating both entities works fine but inserting doesn´t work. I get "Object reference not set to an instance of an object." in " System.Web.UI.WebControls.EntityDataSourceView.ConvertWCProperty(IDictionary values, Dictionary`2 convertedValues, List`1 visitedProperties, PropertyDescriptor pd, ParameterCollection referenceParameters, Dictionary`2& exceptions)"
Here is my code:
cs-file:
The last bit with insertParameters is only a guess from my side, seeing others having problems with this using sql but it might not apply to entitys?
I also attached a screenshot of the relevant entities.
Im using asp.net 3.5 sp1 with a mysql-adapter.
Telerik.Web.UI 2009.3.1314.35
I try to use a hierarchical grid using entity-data. Viewing, updating both entities works fine but inserting doesn´t work. I get "Object reference not set to an instance of an object." in " System.Web.UI.WebControls.EntityDataSourceView.ConvertWCProperty(IDictionary values, Dictionary`2 convertedValues, List`1 visitedProperties, PropertyDescriptor pd, ParameterCollection referenceParameters, Dictionary`2& exceptions)"
Here is my code:
| <asp:EntityDataSource ID="ordersDS" runat="server" ConnectionString="name=oscEnties" |
| DefaultContainerName="oscEnties" EnableDelete="False" EnableInsert="True" EnableUpdate="True" |
| EntitySetName="i_orders" Include="orderparts"> |
| </asp:EntityDataSource> |
| <asp:EntityDataSource ID="orderpartDS" runat="server" ConnectionString="name=oscEnties" |
| DefaultContainerName="oscEnties" EnableDelete="false" EnableInsert="True" EnableUpdate="True" |
| EntitySetName="i_orderpart" Where="it.order.orderid==@orderid"> |
| <InsertParameters> |
| <asp:Parameter Name="order.orderid" Type="Int32" /> |
| </InsertParameters> |
| </asp:EntityDataSource> |
| <telerik:RadGrid ID="ordersGrid" runat="server" ShowGroupPanel="True" GridLines="None" |
| OnItemCommand="ordersGrid_ItemCommand" AllowAutomaticInserts="True" DataSourceID="ordersDS" |
| AllowFilteringByColumn="True" AllowAutomaticUpdates="true" AllowSorting="True" |
| AutoGenerateColumns="False"> |
| <HeaderContextMenu> |
| <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> |
| </HeaderContextMenu> |
| <ClientSettings AllowKeyboardNavigation="true" EnablePostBackOnRowClick="true"> |
| <Selecting AllowRowSelect="true" /> |
| </ClientSettings> |
| <MasterTableView GroupLoadMode="client" AutoGenerateColumns="False" DataKeyNames="orderid" |
| CommandItemDisplay="Top"> |
| <DetailTables> |
| <telerik:GridTableView DataSourceID="orderpartDS" DataKeyNames="orderpartid" AutoGenerateColumns="false" |
| AllowAutomaticUpdates="true" AllowAutomaticInserts="true" CommandItemDisplay="Top" |
| AllowFilteringByColumn="false"> |
| <ParentTableRelation> |
| <telerik:GridRelationFields DetailKeyField="orderid" MasterKeyField="orderid" /> |
| </ParentTableRelation> |
| <NoRecordsTemplate> |
| Hittade inga orderdelar |
| </NoRecordsTemplate> |
| <Columns> |
| <telerik:GridBoundColumn DataField="orderpartid" DataType="System.Int32" HeaderText="ID" |
| ReadOnly="True" SortExpression="orderpartid" UniqueName="orderpartid"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="ordername" HeaderText="Namn" SortExpression="ordername" DataType="System.String" |
| UniqueName="ordername"> |
| </telerik:GridBoundColumn> |
| <telerik:GridDateTimeColumn DataField="orderdate" DataType="System.DateTime" DataFormatString="{0:d}" |
| HeaderText="Ankommande" UniqueName="orderdate" SortExpression="orderdate"> |
| </telerik:GridDateTimeColumn> |
| <telerik:GridDateTimeColumn DataField="shippingdate" DataType="System.DateTime" DataFormatString="{0:d}" |
| HeaderText="Ankommande" UniqueName="shippingdate" SortExpression="shippingdate"> |
| </telerik:GridDateTimeColumn> |
| <telerik:GridDateTimeColumn DataField="arrivaldate" DataType="System.DateTime" DataFormatString="{0:d}" |
| HeaderText="Ankommande" UniqueName="arrivaldate" SortExpression="arrivaldate"> |
| </telerik:GridDateTimeColumn> |
| <telerik:GridNumericColumn DataField="currency" DataType="System.Double" HeaderText="Växelkurs" |
| UniqueName="currency" SortExpression="currency" NumericType="Number" KeepNotRoundedValue="true"> |
| </telerik:GridNumericColumn> |
| <telerik:GridNumericColumn DataField="freightcost" DataType="System.Double" HeaderText="Fraktkostnad" |
| UniqueName="freightcost" SortExpression="freightcost" NumericType="Number" KeepNotRoundedValue="true"> |
| </telerik:GridNumericColumn> |
| <telerik:GridNumericColumn DataField="order.orderid" DataType="System.Int32" HeaderText="OrderId" |
| UniqueName="order.orderid" SortExpression="order.orderid" Visible="true" ReadOnly="false"> |
| </telerik:GridNumericColumn> |
| <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn"> |
| <ItemStyle CssClass="MyImageButton" /> |
| </telerik:GridEditCommandColumn> |
| </Columns> |
| <EditFormSettings ColumnNumber="2" CaptionFormatString="Ändra orderdel"> |
| <FormTableItemStyle Wrap="False"></FormTableItemStyle> |
| <FormCaptionStyle CssClass="EditFormHeader"></FormCaptionStyle> |
| <FormMainTableStyle GridLines="None" CellSpacing="0" CellPadding="1" BackColor="White" |
| Width="100%" /> |
| <FormTableStyle CellSpacing="0" CellPadding="2" Height="60px" BackColor="White" /> |
| <FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle> |
| <EditColumn ButtonType="ImageButton" InsertText="Lägg till" UpdateText="Uppdatera" |
| UniqueName="EditCommandColumn1" CancelText="Avbryt"> |
| </EditColumn> |
| </EditFormSettings> |
| </telerik:GridTableView> |
| </DetailTables> |
| <NoRecordsTemplate> |
| Hittade inga ordrar |
| </NoRecordsTemplate> |
| <Columns> |
| <telerik:GridBoundColumn DataField="orderid" DataType="System.Int32" HeaderText="ID" |
| ReadOnly="True" SortExpression="orderid" UniqueName="orderid"> |
| </telerik:GridBoundColumn> |
| <telerik:GridCheckBoxColumn DataField="open" DataType="System.SByte" HeaderText="Öppen för best." |
| SortExpression="open" UniqueName="open"> |
| </telerik:GridCheckBoxColumn> |
| <telerik:GridBoundColumn DataField="ordername" HeaderText="Namn" SortExpression="ordername" |
| UniqueName="ordername"> |
| </telerik:GridBoundColumn> |
| <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn"> |
| <ItemStyle CssClass="MyImageButton" /> |
| </telerik:GridEditCommandColumn> |
| </Columns> |
| <EditFormSettings ColumnNumber="2" CaptionDataField="ordername" CaptionFormatString="Ändra på order: {0}"> |
| <FormTableItemStyle Wrap="False"></FormTableItemStyle> |
| <FormCaptionStyle CssClass="EditFormHeader"></FormCaptionStyle> |
| <FormMainTableStyle GridLines="None" CellSpacing="0" CellPadding="1" BackColor="White" |
| Width="100%" /> |
| <FormTableStyle CellSpacing="0" CellPadding="2" Height="60px" BackColor="White" /> |
| <FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle> |
| <EditColumn ButtonType="ImageButton" InsertText="Lägg till" UpdateText="Uppdatera" |
| UniqueName="EditCommandColumn1" CancelText="Avbryt"> |
| </EditColumn> |
| </EditFormSettings> |
| </MasterTableView> |
| <ClientSettings AllowDragToGroup="True"> |
| </ClientSettings> |
| <FilterMenu> |
| <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> |
| </FilterMenu> |
| </telerik:RadGrid> |
cs-file:
| public partial class Orders : System.Web.UI.Page |
| { |
| protected void Page_Load(object sender, EventArgs e) |
| { |
| if (!IsPostBack) |
| orderpartDS.WhereParameters.Add(new SessionParameter() { Name = "orderid", SessionField = "orderid", Type = TypeCode.Int32 }); |
| } |
| protected void ordersGrid_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e) |
| { |
| if (e.CommandName == RadGrid.PerformInsertCommandName) |
| { |
| if (e.Item.OwnerTableView.DataSourceID == "orderpartDS") |
| { |
| GridDataItem parentItem = (GridDataItem)(e.Item.OwnerTableView.ParentItem); |
| if (parentItem != null) |
| { |
| string orderId = parentItem.OwnerTableView.DataKeyValues[parentItem.ItemIndex]["orderid"].ToString(); |
| orderpartDS.InsertParameters["order.orderid"].DefaultValue = orderId; |
| } |
| } |
| } |
| } |
| } |
The last bit with insertParameters is only a guess from my side, seeing others having problems with this using sql but it might not apply to entitys?
I also attached a screenshot of the relevant entities.
Im using asp.net 3.5 sp1 with a mysql-adapter.
Telerik.Web.UI 2009.3.1314.35