This is a migrated thread and some comments may be shown as answers.

Rebind grid error after update the details table

3 Answers 169 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tom
Top achievements
Rank 1
Tom asked on 02 Nov 2010, 04:32 PM
Hi,

Please help.
I am getting this error:
Sys.WebForms.PageRequestManagerServerErrorException: There was a problem extracting DataKeyValues from the DataSource. Please ensure that DataKeyNames are specified correctly and all fields specified exist in the DataSource.

When I update the order item with OrderDetail_UpdateCommand and then gridCustomer.Rebind() and I get the error I mentioned above.   Please help. Thanks.

ASPX:

<telerik:RadGrid ID="gridCustomer" runat="server" OnNeedDataSource="gridCustomer_NeedDataSource" 
OnUpdateCommand="OrderDetail_UpdateCommand" OnDetailTableDataBind="gridOrder_DetailTableDataBind"
   <MasterTableView DataKeyNames="CustomerID" Width="100%" PageSize="20"   ClientDataKeyNames="CustomerID"
      <DetailTables> 
         <telerik:GridTableView DataKeyNames="OrderID" Name="OrderDetail"  EditMode="InPlace"
         <Columns> 
            <telerik:GridBoundColumn 
               DataField="OrderName" 
               HeaderText="Order Name" 
               ReadOnly="true"/> 
            <telerik:GridBoundColumn 
               DataField="DateReceived" 
               HeaderText="Date Received" 
               ReadOnly="true" /> 
            <telerik:GridTemplateColumn 
               HeaderText="Amount to Pay" 
               EditFormColumnIndex="1" 
               HeaderStyle-Width="140px"
               <ItemTemplate> 
                   <asp:Label runat="server" ID="lblAmountToPay" Text='<%# Eval ("AmountToPay", "{0:C}") %>'> </asp:Label>
               </ItemTemplate>
               <EditItemTemplate>
                   <telerik:RadNumericTextBox runat="server" ID="tbxUnitPrice" Width="40px" DbValue='<%# Bind("AmountToPay") %>'
                   </telerik:RadNumericTextBox> 
               </EditItemTemplate> 
            </telerik:GridTemplateColumn> 
           <telerik:GridEditCommandColumn UniqueName="EditOrderPrice" /> 
        </Columns>
    </telerik:GridTableView> 
</DetailTables> 
<Columns> 
    <telerik:GridClientSelectColumn UniqueName="ClientSelectColumn" /> 
    <telerik:GridBoundColumn DataField="CustomerName" HeaderText="Customer Name"
    </telerik:GridBoundColumn> 
    <telerik:GridBoundColumn DataField="Address" HeaderText="Address"
    </telerik:GridBoundColumn>
    <telerik:GridBoundColumn DataField="Phone" HeaderText="Phone"
    </telerik:GridBoundColumn> 
    <telerik:GridBoundColumn DataField="Email" HeaderText="Email"
    </telerik:GridBoundColumn>
    <telerik:GridBoundColumn DataField="Group" HeaderText="Group"
    </telerik:GridBoundColumn> 
  </Columns> 
</MasterTableView> 
<ClientSettings> 
<Selecting AllowRowSelect="True" /> 
<ClientEvents OnRowSelected="GridCustomerRowSelected" /> 
</ClientSettings> 
</telerik:RadGrid>

CODE BEHIND

protected void gridCustomer_NeedDataSource(object source, GridNeedDataSourceEventArgs e) { 
       gridCustomer.DataSource = ClaimProcess.GetCustomer();
}
  
protected void gridOrder_DetailTableDataBind(object source, GridDetailTableDataBindEventArgs e) { 
      switch (e.DetailTableView.Name) 
      {
         case "OrderDetail"
         {
             GridDataItem dataItem = e.DetailTableView.ParentItem; 
             e.DetailTableView.DataSource = ClaimProcess.GetOrder(dataItem.GetDataKeyValue("CustomerID")); 
             break
         }
      }
}
  
protected void OrderDetail_UpdateCommand(object source, GridCommandEventArgs e) 
{
    GridEditableItem item = (GridEditableItem)e.Item; 
    int OrderID = Convert.ToInt32(item.GetDataKeyValue("OrderID")); 
    RadNumericTextBox txtAmountPay = (RadNumericTextBox)e.Item.FindControl("tbxUnitPrice"); 
    UpdateOrder(OrderID, Convert.ToDouble(txtAmountPay.Text));
    gridCustomer.Rebind(); 
}

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 03 Nov 2010, 06:05 AM
Hello Tom,

Try the following changes in your code and check whether this eliminates the error.

C#:
protected void OrderDetail_UpdateCommand(object source, GridCommandEventArgs e)
  {
          GridEditableItem item = (GridEditableItem)e.Item;
          int OrderID = Convert.ToInt32(item.GetDataKeyValue("OrderID"));
          RadNumericTextBox txtAmountPay = (RadNumericTextBox)e.Item.FindControl("tbxUnitPrice");
          UpdateOrder(OrderID, Convert.ToDouble(txtAmountPay.Text));
          e.Item.OwnerTableView.Rebind();
  }

Thanks,
Princy.
0
Tom
Top achievements
Rank 1
answered on 03 Nov 2010, 02:57 PM

Hi Princy,

I just tried and the error goes away but it's does not refresh the entire grid, also all the detail grid rows are duplicate.  I also tried

e.Item.OwnerTableView.Rebind();
gridCustomer.Rebind();

Again no error, all detail grid rows are duplicate, and the inline edit box still there.

Thanks,
Tom
0
Tom
Top achievements
Rank 1
answered on 04 Nov 2010, 10:54 PM
Is there solution to this problem?
I am trying all different ways but couldn't do it.

Thanks,
Tom
Tags
Grid
Asked by
Tom
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Tom
Top achievements
Rank 1
Share this question
or