Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <asp:DropDownList ID="ddlMesReajuste" runat="server" AppendDataBoundItems="true">
- <asp:ListItem Value="" Text="Selecione o mês de reajuste" Selected></asp:ListItem>
- <asp:ListItem Value="Janeiro" Text="Janeiro"></asp:ListItem>
- <asp:ListItem Value="Fevereiro" Text="Fevereiro"></asp:ListItem>
- <asp:ListItem Value="Março" Text="Março"></asp:ListItem>
- <asp:ListItem Value="Abril" Text="Abril"></asp:ListItem>
- <asp:ListItem Value="Maio" Text="Maio"></asp:ListItem>
- <asp:ListItem Value="Junho" Text="Junho"></asp:ListItem>
- <asp:ListItem Value="Julho" Text="Julho"></asp:ListItem>
- <asp:ListItem Value="Agosto" Text="Agosto"></asp:ListItem>
- <asp:ListItem Value="Setembro" Text="Setembro"></asp:ListItem>
- <asp:ListItem Value="Outubro" Text="Outubro"></asp:ListItem>
- <asp:ListItem Value="Novembro" Text="Novembro"></asp:ListItem>
- <asp:ListItem Value="Dezembro" Text="Dezembro"></asp:ListItem>
- </asp:DropDownList>
- <asp:DropDownList ID="ddlMesReajuste" runat="server">
- </asp:DropDownList>
- public void PopularDropDown()
- {
- int quantidadeMesesAdicional = 1;
- if (DateTime.Today.Day > 11)
- quantidadeMesesAdicional = 2;
- int indiceMes = DateTime.Today.Month + quantidadeMesesAdicional;
- //Se o indice for 13 irá voltar para 1 que é Janeiro.
- //Se o indice for 14 irá voltar para 2 que é Fevereiro.
- if (indiceMes == 13)
- indiceMes = 1;
- else if (indiceMes == 14)
- indiceMes = 2;
- Dictionary<byte, string> dictionaryDatas = new Dictionary<byte, string>();
- dictionaryDatas.Add(1, "Janeiro");
- dictionaryDatas.Add(2, "Fevereiro");
- dictionaryDatas.Add(3, "Março");
- dictionaryDatas.Add(4, "Abril");
- dictionaryDatas.Add(5, "Maio");
- dictionaryDatas.Add(6, "Junho");
- dictionaryDatas.Add(7, "Julho");
- dictionaryDatas.Add(8, "Agosto");
- dictionaryDatas.Add(9, "Setembro");
- dictionaryDatas.Add(10, "Outubro");
- dictionaryDatas.Add(11, "Novembro");
- dictionaryDatas.Add(12, "Dezembro");
- ListItemCollection lista = new ListItemCollection();
- foreach (var data in dictionaryDatas.Where(w => w.Key >= indiceMes))
- {
- lista.Add(new ListItem(data.Value, data.Value));
- }
- ddlMesReajuste.DataSource = lista;
- ddlMesReajuste.DataBind();
- }
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- PopularDropDown();
- }
- }
Add Comment
Please, Sign In to add comment