Filter Expression for a DataTable


/ Published in: C#
Save to your folder(s)

Pretty intuitive, might be an easier/simpler way.


Copy this code and paste it in your HTML
  1. //This was the hard way.
  2. public static Lookup.StatusDataTable GetStatuses(bool intranetMode)
  3. {
  4. //TODO: Handle Intranet vs Internet mode.
  5. LookupTableAdapters.StatusTableAdapter sta = new LookupTableAdapters.StatusTableAdapter();
  6. Lookup.StatusDataTable sdt = sta.GetStatusData();
  7. DataRow[] rows = sdt.Select("Status <> 'Unapproved' and Status <> 'Closed'");
  8. Lookup.StatusDataTable retVal = new Lookup.StatusDataTable();
  9. foreach(DataRow dr in rows)
  10. {
  11. retVal.Rows.Add(dr.ItemArray);
  12. }
  13. return retVal;
  14. }
  15.  
  16. //Here's the easy way:
  17. public static Lookup.StatusDataTable GetStatuses(bool intranetMode)
  18. {
  19. LookupTableAdapters.StatusTableAdapter sta = new LookupTableAdapters.StatusTableAdapter();
  20. Lookup.StatusDataTable sdt = sta.GetStatusData();
  21. if (!intranetMode)
  22. {
  23. sdt.DefaultView.RowFilter = "Status <> 'Unapproved' and Status <> 'Closed'";
  24. }
  25. return sdt;
  26. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.