更新记录后,辐射网格数据为空



我有一个与实体数据源绑定的radgrid。一切都运行良好,除了当我在 updateCommand 上从代码隐藏更新记录时,数据从网格中丢失,并且在数据库中更新了记录。请帮助。下面是用于更新记录的代码。

谢谢。

 protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e)
        {
            try
            {
                 var editItem = (GridEditableItem)e.Item;
                 var values = _extractEpisodePrograms(editItem);
                 var gettingEpisodeProgramDiagnosis_ID = (int)editItem.GetDataKeyValue("EpisodeProgramDiagnosis_ID");
                 using (HSS_Swirl_WebEntities context = new HSS_Swirl_WebEntities())
                 {
                     var EpisodeProgramDiagnosis = context.ClientEpisodeProgramDiagnosis.First(t => t.EpisodeProgramDiagnosis_ID == gettingEpisodeProgramDiagnosis_ID);
                     EpisodeProgramDiagnosis.EpisodeProgram_ID = 39;
                     EpisodeProgramDiagnosis.ConditionOnset = (bool)values["ConditionOnset"];
                     EpisodeProgramDiagnosis.OtherDiagnosis = false;
                     EpisodeProgramDiagnosis.PrimaryDiagnosis = (bool)values["PrimaryDiagnosis"];
                     EpisodeProgramDiagnosis.ICD10Diagnosis_ID = 11;
                     var CheckingDuplicateKeys = (from p in context.ClientEpisodeProgramDiagnosis where p.EpisodeProgram_ID == EpisodeProgramDiagnosis.EpisodeProgram_ID && p.ICD10Diagnosis_ID == EpisodeProgramDiagnosis.ICD10Diagnosis_ID select p).FirstOrDefault();
                     if (CheckingDuplicateKeys == null)
                     {
                         context.SaveChanges();
                     }
                     else {
                         ShowErrorMessage("You cannot enter duplicate values for ICD10Diagnosis_ID and EpisodeProgram_ID");
                     }
                 }
            }
            catch (Exception ex)
            {
                var insertException = new CustomValidator();
                insertException.IsValid = false;
                insertException.ErrorMessage = (ex.InnerException != null) ? ex.InnerException.ToString() : ex.Message;
                Page.Validators.Add(insertException);
            }
            RadGrid1.Rebind();
        } 

尝试在 RadGrid 的 NeedDataSource 事件中设置数据源,如下所示:

protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    RadGrid1.DataSource = myDataSource;
}

请记住将RadGrid1_NeedDataSource连接到 RadGrid1 中的 OnNeedDataSource 事件。

您也可以尝试在重新绑定之前再次设置数据源,如下所示:

RadGrid1.DataSource = myDataSource;
RadGrid1.Rebind();

相关内容

  • 没有找到相关文章

最新更新