Tuesday, November 15, 2022

AND OR operator in Exists function LINQ - ASP.NET C# - without model or entity

var dt = GridView1.DataSource as DataTable;

                var a= dt.AsEnumerable().GroupBy(s => s.Field<string>("Discipline").ToString());

                

                

                //dt.DefaultView.Sort = sort;

                var final = dt.AsEnumerable().GroupBy(x => x.Field<string>("Discipline"), (key, g) => g.OrderByDescending(s => DateTime.ParseExact(s.Field<string>("PresentInstitutePostingDate") == ""?"01/01/1990": s.Field<string>("PresentInstitutePostingDate"), "mm/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture)).First()).Select(t=> new { PresentInstitutePostingDate = (DateTime.ParseExact(t.Field<string>("PresentInstitutePostingDate") == "" ? "01/01/1990" : t.Field<string>("PresentInstitutePostingDate"), "mm/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture)), Discipline= t.Field<string>("Discipline") });

                var tt = final.ToList();

  if (tt.Exists(o => o.PresentInstitutePostingDate == DateTime.ParseExact(DataBinder.Eval(e.Row.DataItem, "PresentInstitutePostingDate").ToString(), "mm/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture) && o.Discipline == DataBinder.Eval(e.Row.DataItem, "Discipline").ToString()))

                    {

                        e.Row.BackColor = System.Drawing.ColorTranslator.FromHtml("#0000ff");

                    }

No comments:

Post a Comment