MBindUI.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using System;
  2. using System.Web.UI.WebControls;
  3. using System.Text;
  4. using System.Web.UI;
  5. using Win = System.Windows.Forms;
  6. using Ant.ORM.Table;
  7. namespace Ant.ORM
  8. {
  9. internal class MBindUI
  10. {
  11. public static void Bind(object ct,object source)
  12. {
  13. if (ct is GridView)
  14. {
  15. ((GridView)ct).DataSource = source;
  16. ((GridView)ct).DataBind();
  17. }
  18. else if (ct is Repeater)
  19. {
  20. ((Repeater)ct).DataSource = source;
  21. ((Repeater)ct).DataBind();
  22. }
  23. else if (ct is DataList)
  24. {
  25. ((DataList)ct).DataSource = source;
  26. ((DataList)ct).DataBind();
  27. }
  28. else if (ct is DataGrid)
  29. {
  30. ((DataGrid)ct).DataSource = source;
  31. ((DataGrid)ct).DataBind();
  32. }
  33. else if (ct is Win.DataGrid)
  34. {
  35. ((DataGrid)ct).DataSource = source;
  36. }
  37. else if (ct is Win.DataGridView)
  38. {
  39. ((System.Windows.Forms.DataGridView)ct).DataSource = source;
  40. }
  41. }
  42. public static void BindList(object ct, MDataTable source)
  43. {
  44. if (ct is ListControl)
  45. {
  46. BindList(ct as ListControl, source);
  47. }
  48. else
  49. {
  50. BindList(ct as Win.ListControl, source);
  51. }
  52. }
  53. private static void BindList(Win.ListControl listControl, MDataTable source)
  54. {
  55. listControl.DataSource = source;
  56. listControl.DisplayMember = source.Columns[0].ColumnName;
  57. listControl.ValueMember = source.Columns[1].ColumnName;
  58. }
  59. private static void BindList(ListControl listControl, MDataTable source)
  60. {
  61. listControl.DataSource = source;
  62. listControl.DataTextField = source.Columns[0].ColumnName;
  63. listControl.DataValueField = source.Columns[1].ColumnName;
  64. listControl.DataBind();
  65. }
  66. public static string GetID(object ct)
  67. {
  68. if (ct is Control)
  69. {
  70. return ((Control)ct).ID;
  71. }
  72. else if (ct is Win.Control)
  73. {
  74. return ((Win.Control)ct).Name;
  75. }
  76. return "cyq";
  77. }
  78. }
  79. }