Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
120
Requested record cannot be found by key
posted

I'm binding a WebDataGrid on a OnSelectedIndexChanged event which works fine. However I'm using an UnboundCheckBoxField and if I select checkbox in the header, then deselect one or more rows, and change the selection from the dropdownlist, I get the above error. 

I am not concerned with keeping previously checked values so I just clear DataSource, dehydrate, and rebind.

protected void serviceTypeFamilyDropDown_OnSelectedIndexChanged(object sender, EventArgs e)

{
  using (DropDownList serviceTypeFamilyDropDown = sender as DropDownList)
  {
    servicesGrid.ClearDataSource();
    servicesGrid.DataSource = ExportableServiceVisits.GetServiceVisitsByServiceTypeFamily(
      serviceTypeFamilyDropDown.SelectedItem.Value.GetDoubleOrIntValue<int>(),
      serviceDatePicker.Date);
    servicesGrid.DataBind();
  }
}

Following suggestions from this forum I created a property on the page and upon OnSelectedIndexChanged I updated the data of the property then on servicesGrid_OnPreRender, I cleared the DataSource, set the DataSource to the property and rebound. However, the error was thrown before OnPreRender() was executed.

private IEnumerable<ExportableServiceVisits> ServiceVisits { get; set; }

protected void serviceTypeFamilyDropDown_OnSelectedIndexChanged(object sender, EventArgs e)
{
  using (DropDownList serviceTypeFamilyDropDown = sender as DropDownList)
  {
    ServiceVisits = ExportableServiceVisits.GetServiceVisitsByServiceTypeFamily(
    serviceTypeFamilyDropDown.SelectedItem.Value.GetDoubleOrIntValue<int>(),
    serviceDatePicker.Date);
  }
}

protected void servicesGrid_OnPreRender(object sender, EventArgs e)
{
  servicesGrid.ClearDataSource();
  servicesGrid.DataSource = ServiceVisits;
  servicesGrid.DataBind();
}

What's the problem?

Parents
No Data
Reply Children