更新记录后,Radgrid数据为空

时间:2014-12-19 04:31:06

标签: c# telerik radgrid entitydatasource

我有一个带有实体数据源的radgrid绑定。除了当我从updateCommand后面的代码更新记录时,数据从网格和数据库中丢失,记录被更新。请帮助this.below是代码更新记录。

先谢谢。

 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();
        } 

1 个答案:

答案 0 :(得分:0)

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

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

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

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

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