Hi Infragistics,
I have a Webdatagrid in an AJAX ModalPopup with a asp:DropDownList above the grid. What the user has to do is to select a picklist in the asp:DropDownList and the picklist items will be shown in the Webdatagrid. If the user select any of the picklist in the asp:DropDownList without doing any modification in the grid or modify something AND push the save button, there will have no problem. The issue appears when the user add a new row and add an item or modify a current row and choose another picklist without save anything. A message will be show:
Requested record cannot be found by key
Is there something I miss?
Thanks in advance!
Christ1
Hello Christ1,
Please assign a column key to DataKeyFields property, it must be unique for the grid data. The grid needs of such identifier in order to work correctly. Usually the primery key of the database table that the grid is boud to is used as DataKeyFields . Keep in mind that Sorting, Filtering, Selection, Editing, almost all grid behaviors(features), rely on unique datakeyfield.
Hope this heps.
Hi Radoslav,
Thank you for the fast reply, that was fast! Unfortunately, This doesn't fix my issue because I already do that in my code
I provide you my code to make it clearer:
<ig:webdatagrid id="wdgItemList" runat="server" autocrud="False" height="184px" width="870px" autogeneratecolumns="False" bordercolor="Black" borderwidth="1px" borderstyle="Solid" datakeyfields="PickListEntryID" enabledataviewstate="True"> <Columns> <ig:BoundDataField DataFieldName="PickListEntryID" Width="1px" Key="PickListEntryID" Hidden="true" DataType="System.Int32" > </ig:BoundDataField> <ig:BoundDataField DataFieldName="PickListID" Width="1px" Key="PickListID" Hidden="true" DataType="System.Int32"> </ig:BoundDataField> <ig:BoundDataField DataFieldName="TxtID" Width="1px" Key="TxtID" Hidden="true" DataType="System.String"> </ig:BoundDataField> <ig:BoundDataField DataFieldName="Name" Width="97%" Key="Name" DataType="System.String"> <Header Text="Nom de l'item" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="Description" Width="1px" Key="Description" Hidden="true" DataType="System.String"> </ig:BoundDataField> <ig:TemplateDataField Key="Delete" Width="16px"> <ItemTemplate> <asp:ImageButton ID="imgDelete" OnCommand="DeleteItem" OnClientClick='<%# BuildMessage(Eval("Name").toString)%>' CommandArgument='<%# Eval("PickListEntryID").toString%>' CommandName="Delete" ImageUrl="~/images/button_cancel.png" runat="server" Width="16px" Height="16px" ToolTip="Supprime un item de la liste" /> </ItemTemplate> </ig:TemplateDataField> </Columns> <Behaviors> <ig:Paging PagerAppearance="Bottom" PageSize="8" Enabled="false" /> <ig:Selection CellClickAction="Row" Enabled="true" /> <ig:EditingCore> <Behaviors> <ig:CellEditing EditModeActions-EnableF2="true" EditModeActions-EnableOnActive="true" EditModeActions-EnableOnKeyPress="true" EditModeActions-MouseClick="None" Enabled="true"> <EditModeActions EnableF2="true" EnableOnActive="True" EnableOnKeyPress="True" MouseClick="Single" /> </ig:CellEditing> </Behaviors> </ig:EditingCore> <ig:Sorting AscendingImageUrl="~/images/spacer.gif" DescendingImageUrl="~/images/spacer.gif"> <ColumnSettings> <ig:SortingColumnSetting ColumnKey="PickListEntryID" Sortable="False" /> <ig:SortingColumnSetting ColumnKey="PickListID" Sortable="False" /> <ig:SortingColumnSetting ColumnKey="TxtID" Sortable="False" /> <ig:SortingColumnSetting ColumnKey="Name" /> <ig:SortingColumnSetting ColumnKey="Description" Sortable="False" /> <ig:SortingColumnSetting ColumnKey="Delete" Sortable="False" /> </ColumnSettings> </ig:Sorting> <ig:Activation> <AutoPostBackFlags ActiveCellChanged="false" /> </ig:Activation> </Behaviors> </ig:webdatagrid>
Hey Christ1, thank you for the code, let me reiterate through the issue per my understanding.
"The issue appears when the user add a new row and add an item or modify a current row and choose another picklist without save anything. A message will be show:
Requested record cannot be found by key"
The grid would act in this way if either modified or added row(record) is posted back to the server and cannot be found in the data source that the grid is bound to. By defalut the grid has an Ajax turned on and when the user does mofificaiton and in case the focus is lost from the edited row Ajax call is made. in this case the grid will raise RowAdding or RowUpdating events on the server passing all the chnages as parameters. These events are supposed to be points where the datasource should be updated.
If you would like to have a batch operations in place, you need to specify that, meaning that the ability to add, edit, delete mulitple rows and all changes to be posted to the server when either by the grid or by another component does the postback on the page. The same events will be raised and you can have there your logic for persisting data.
If you still has troubles, please pack up the code above with its back-end and attached it here, I will try to modify it and make it works for you.