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
425
Error: Requested record cannot be found by key when I change the SelectCommand of a DataSource
posted

I have this grid below

ig:WebDataGrid StyleSetName="Office2007Black" ID="WebDataGridNotas" runat="server" DataSourceID="AccessDataSourceNotas" ItemCssClass="borderClass"
Height="425px" Width="100%" AutoGenerateColumns="False" DataKeyFields="CodNotaMensal"

And I have the DataSource with a SelectCommand and an UpdateCommand that works fine when I am updating rows using client-side editing.

But when the user select a new value in a DropDownBox, I use this value to change the SelectCommand (just the WHERE clause) using codebehind triggered by the Change event of that DropDownBox. Then when I try to edit the same row I receive the "Requested record cannot be found by key"

Here is the CodeBehind

protected void WebDropDownDisciplina_SelectionChanged(object sender, Infragistics.Web.UI.ListControls.DropDownSelectionChangedEventArgs e)
{
notas.etapa = Convert.ToInt32(WebDropDownEtapa.SelectedValue);
notas.codUnidade = Convert.ToInt32(WebDropDownUnidade.SelectedValue);
notas.codGrau = Convert.ToInt32(WebDropDownGrau.SelectedValue);
notas.codSerie = Convert.ToString(WebDropDownSerie.SelectedValue);
notas.codTurma = Convert.ToString(WebDropDownTurma.SelectedValue);
notas.codDisciplina = Convert.ToInt32(WebDropDownDisciplina.SelectedValue);
notas.matriculaProfessor = Convert.ToInt32(WebDropDownProfessor.SelectedValue);
string selectCommand = "SELECT * FROM [NotasAvaliacaoSelect" + notas.etapa + "] WHERE ([NOTA-MENSAL].CodUnidade =" + notas.codUnidade + ") AND ([NOTA-MENSAL].CodGrau=" + notas.codGrau + ") AND ([NOTA-MENSAL].CodSérie='" + notas.codSerie + "') AND ([NOTA-MENSAL].Turma='" + notas.codTurma + "') AND ([NOTA-MENSAL].CodDisciplina=" + notas.codDisciplina + ") AND ([AULA].MatrículaProfessor=" + notas.matriculaProfessor + ") ORDER BY [NúmeroPauta]";
//string updateCommand = "UPDATE [NotasAvaliacaoUpdate" + notas.etapa + "] SET Faltas = ?, Avaliação1 = ?, Avaliação2 = ?, Avaliação3 = ?, Avaliação4 = ?, Avaliação5 = ?, Avaliação6 = ?, Avaliação7 = ?, Avaliação8 = ?, Avaliação9 = ?, Avaliação10 = ? WHERE (CodNotaMensal = ?)";
AccessDataSourceNotas.SelectCommand = selectCommand;
//AccessDataSourceNotas.UpdateCommand = updateCommand;
//AccessDataSourceNotas.DataBind();
WebDataGridNotas.ClearDataSource();
WebDataGridNotas.DataSourceID = AccessDataSourceNotas.ID;
WebDataGridNotas.DataKeyFields = "CodNotaMensal";
WebDataGridNotas.DataBind();
}

Parents
No Data
Reply
  • 29417
    Offline posted

    Hello Edson,

     

    Thank you for posting in our forum.

     

    Are you updating any of the values in the grid before you change the data source?

    Make sure that all changes have been committed before the data source is changed otherwise the grid will not be able to commit the changes since the rows in it will be changed before the updating events have taken place .

    Check of the selection changes is fired before the RowUpdating event and if it does then either:

    1)      Change the data source later in the page lifecycle (for example on Page_PreRender). In that way all the changes will be committed  during the RowUpdating/ed events and then only then the data source will be changed.

    2)      Commit the changes manually  for example on ExitedEditMode client side event of the cell. In that case the changes would be directly committed to the data source via an ajax callback when you exit edit mode of a cell whose value has been changed. You can manually commit the data in the grid using the commit method: grid.get_behaviors().get_editingCore().commit();

     

     

    Let me know if you have any questions or concerns.

     

    Best Regards,

    Maya Kirova

    Developer Support Engineer II

    Infragistics, Inc.

    http://es.infragistics.com/support

     

Children