Guest User

Untitled

a guest
Jun 22nd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. <asp:DropDownList ID="ddlMesReajuste" runat="server" AppendDataBoundItems="true">
  2. <asp:ListItem Value="" Text="Selecione o mês de reajuste" Selected></asp:ListItem>
  3. <asp:ListItem Value="Janeiro" Text="Janeiro"></asp:ListItem>
  4. <asp:ListItem Value="Fevereiro" Text="Fevereiro"></asp:ListItem>
  5. <asp:ListItem Value="Março" Text="Março"></asp:ListItem>
  6. <asp:ListItem Value="Abril" Text="Abril"></asp:ListItem>
  7. <asp:ListItem Value="Maio" Text="Maio"></asp:ListItem>
  8. <asp:ListItem Value="Junho" Text="Junho"></asp:ListItem>
  9. <asp:ListItem Value="Julho" Text="Julho"></asp:ListItem>
  10. <asp:ListItem Value="Agosto" Text="Agosto"></asp:ListItem>
  11. <asp:ListItem Value="Setembro" Text="Setembro"></asp:ListItem>
  12. <asp:ListItem Value="Outubro" Text="Outubro"></asp:ListItem>
  13. <asp:ListItem Value="Novembro" Text="Novembro"></asp:ListItem>
  14. <asp:ListItem Value="Dezembro" Text="Dezembro"></asp:ListItem>
  15. </asp:DropDownList>
  16.  
  17. <asp:DropDownList ID="ddlMesReajuste" runat="server">
  18. </asp:DropDownList>
  19.  
  20. public void PopularDropDown()
  21. {
  22. int quantidadeMesesAdicional = 1;
  23.  
  24. if (DateTime.Today.Day > 11)
  25. quantidadeMesesAdicional = 2;
  26.  
  27. int indiceMes = DateTime.Today.Month + quantidadeMesesAdicional;
  28.  
  29. //Se o indice for 13 irá voltar para 1 que é Janeiro.
  30. //Se o indice for 14 irá voltar para 2 que é Fevereiro.
  31. if (indiceMes == 13)
  32. indiceMes = 1;
  33. else if (indiceMes == 14)
  34. indiceMes = 2;
  35.  
  36. Dictionary<byte, string> dictionaryDatas = new Dictionary<byte, string>();
  37.  
  38. dictionaryDatas.Add(1, "Janeiro");
  39. dictionaryDatas.Add(2, "Fevereiro");
  40. dictionaryDatas.Add(3, "Março");
  41. dictionaryDatas.Add(4, "Abril");
  42. dictionaryDatas.Add(5, "Maio");
  43. dictionaryDatas.Add(6, "Junho");
  44. dictionaryDatas.Add(7, "Julho");
  45. dictionaryDatas.Add(8, "Agosto");
  46. dictionaryDatas.Add(9, "Setembro");
  47. dictionaryDatas.Add(10, "Outubro");
  48. dictionaryDatas.Add(11, "Novembro");
  49. dictionaryDatas.Add(12, "Dezembro");
  50.  
  51. ListItemCollection lista = new ListItemCollection();
  52.  
  53. foreach (var data in dictionaryDatas.Where(w => w.Key >= indiceMes))
  54. {
  55. lista.Add(new ListItem(data.Value, data.Value));
  56. }
  57.  
  58. ddlMesReajuste.DataSource = lista;
  59. ddlMesReajuste.DataBind();
  60. }
  61.  
  62. protected void Page_Load(object sender, EventArgs e)
  63. {
  64. if (!IsPostBack)
  65. {
  66. PopularDropDown();
  67. }
  68. }
Add Comment
Please, Sign In to add comment