Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. static DataTable Datatable()
  2. {
  3. ubicacion_componentes componenteLocations = new ubicacion_componentes();
  4. DataTable dt = new DataTable();
  5. dt.Columns.Add("ubicacion_componente_id");
  6. dt.Columns.Add("armario");
  7. dt.Columns.Add("cajon");
  8.  
  9. foreach (var cmp in componenteLocations.ubicaction_componentes)
  10. {
  11. var row = dt.NewRow();
  12.  
  13. row["ubicacion_componente_id"] = cmp.ubicacion_componente_id;
  14. row["armario"] = cmp.armario;
  15. row["cajon"] = cmp.cajon;
  16.  
  17. dt.Rows.Add(row);
  18. }
  19. return dt;
  20. }
  21.  
  22. protected void BindGridList(string sortExp, string sortDir)
  23. {
  24. DataTable dt = Datatable();
  25.  
  26. DataView dv = new DataView(dt);
  27. dv = dt.DefaultView;
  28.  
  29. if (sortExp != string.Empty)
  30. {
  31. dv.Sort = string.Format("{0} {1}", sortExp, sortDir);
  32. }
  33. gvLocation.DataSource = dv;
  34. gvLocation.DataBind();
  35.  
  36. if (dt.Rows.Count > 0)
  37. {
  38. gvLocation.DataSource = dt;
  39. gvLocation.DataBind();
  40. }
  41. else
  42. {
  43. dt.Rows.Add(dt.NewRow());
  44. gvLocation.DataSource = dt;
  45. gvLocation.DataBind();
  46. gvLocation.Rows[0].Cells.Clear();
  47. gvLocation.Rows[0].Cells.Add(new TableCell());
  48. gvLocation.Rows[0].Cells[0].ColumnSpan = dt.Columns.Count;
  49. gvLocation.Rows[0].Cells[0].Text = "datos no encontrados";
  50. gvLocation.Rows[0].Cells[0].HorizontalAlign = HorizontalAlign.Center;
  51. }
  52. }
  53.  
  54. public string sortOrder
  55. {
  56. get
  57. {
  58. if (ViewState["sortOrder"].ToString() == "desc")
  59. {
  60. ViewState["sortOrder"] = "asc";
  61. }
  62. else
  63. {
  64. ViewState["sortOrder"] = "desc";
  65. }
  66.  
  67. return ViewState["sortOrder"].ToString();
  68. }
  69. set
  70. {
  71. ViewState["sortOrder"] = value;
  72. }
  73. }
  74.  
  75. protected void gvLocation_Sorting(object sender, GridViewSortEventArgs e)
  76. {
  77. BindGridList(e.SortExpression, sortOrder);
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement