1

Problem solved: Instead of using two dynamic lists, only one list is needed:

ObeservableCollection<dataClass> currentList { get; set; } = new ObservableCollection<dataClass>();

The dataClass stays the same, so does the TelerikGrid. See code below.

The CompareData() function is changed.

public string CompareData(string? SportsName)
{
   if (currentList.Count > 1)
   {
      var i = currentList[0];
      PropertyInfo? obj = i.GetType().GetProperty(SportsName);
      string s = (string)obj.GetValue(i);

      var i1 = currentList[1];
      PropertyInfo? obj1 = i.GetType().GetProperty(SportsName);
      string s1 = (string)obj1.GetValue(i1);

      if (s != s1) 
      {
         return "red";
      }
      else
      {
         return "";
      }
   }
   else
   {
       return "";
   }
}

This solution uses reflection. There could be a better solution but this works for me.


Ouestion: I have two dynamic lists right now

ObeservableCollection<dataClass> currentList { get; set; } = new ObservableCollection<dataClass>();

and

ObeservableCollection<dataClass> previousList { get; set; } = new ObservableCollection<dataClass>();

and my dataClass looks like this:

public class dataClass
{
   public string FullName { get; set; }
   public int SportsId { get; set; }
   public string SportsName { get; set; }
   public DateTime DateOfBirth { get; set; }
}

I have a table using TelerikGrid which shows all the data from currentList. what I am trying to do is to have a cell in the TelerikGrid highlighted when the data in that cell is changed. For example, a person with the same name could be registered in multiple sports so when that happens, only the sportsId and sportsName cells get highlighted.

Using TelerikGrid

<Template>
   var a = context as dataClass;
   var SportsName = instance.SportsName;
   <div class="@CompareData(SportsName)">@instance.SportsName</div>
</Template>

I can use a function in my razor.cs file to do it and I've tried to pass the SportsName from the Telerik Grid into the function but am unsure how to get it right.

public string CompareData(string? SportsName)
{
   string? currentSportsName = SportsName;
string? prevSportsName = **idkwhattoputhereorhowtodoit**;

   if (currentSportsName != prevSportsName) 
   {
      return "red";
   }
   else 
   {
      return "";
   } 
}

My main issue is getting the data from the previousList and using it for comparison.

remdon
  • 23
  • 3
  • Will update this post with the latest approach. This approach doesn't work as the logic is somewhat flawed. – remdon Jun 09 '23 at 03:48

0 Answers0