How to make a combo With the days of the month?

1

What is the best way to do a comboBox with the days of the month?

In other words, the combo has to take from 1 to 31 days.

On the HTML side I have a label called "drpDia", and I need to load this label with numbers from 1 to 31. I know if you can do this in JavaScript, but I do not understand anything about JavaScript, so I was going by C #, in which I know more or less that I have to make a list from 1 to 31 and then I have to fill in the "drpDia" label with those numbers. correct?

Is this a very good thing to identify?

But I'll have to load it on drpDia.

int[] numbers = new int[seats];
for (int i = 1; i <= seats; i++)
{
  numbers[i-1] = i;
}
comboBox1.Items.AddRange(numbers);

example:

So instead of having the days of the week is to have the days of the month where Friday becomes 1, saturday becomes 2 and so on up to 31.

    
asked by anonymous 16.02.2017 / 15:12

3 answers

4

Well, I think I understand your question ...

Assuming you have the month number and% void%, we can do this in a few steps:

First: We need to find out how many days in the month:

 public static IEnumerable<DateTime> GetDiasNoMes(int mes, int? ano = null)
 {
    ano = ano ?? DateTime.Now.Year;
    return Enumerable.Range(1, DateTime.DaysInMonth(ano, mes))  // Dias: 1, 2 ... 31 etc. É um IEnumerable<int>
                     .Select(dia => new DateTime(ano, mes, dia)) // Mapeia as datas;
 }

Second: we need ComboBox popular:

var itens = dataSource.AddRange(GetDiasNoMes(10) //Pega de outubro
                       .Select(data => new SelectListItem
                       {
                           Value = data.Day.ToString(),
                           Text = data.Day.ToString()
                       }); 

comboBox1.Items.Clear(); //Vamos garantir que estaja vazio
comboBox1.Items.AddRange(itens);

Second (Alternative): Using jQuery Ajax to update

Controller:

[HttpGet]
public JsonResult Atualizar(int mes)
{
  var itens = GetDiasNoMes(mes) //Pega do mes 
                         .Select(data => data.Day);
  return Json(itens, JsonRequestBehavior.AllowGet);
}

View:

@Html.DropDownList("Mes", String.Empty)
@Html.DropDownList("Dia", null)

<script type="text/javascript">

$(() => {
   $( '#Mes' ).change( function () { //Quando o mês mudar/for selecionado entramos aqui

      let valor = $( this ).val(); //pegamos o valor

      $.ajax({ //Requisição
        url: '@Url.Action("Atualizar","MeuController")',
        data: { mes : valor }, //passamos o parametro para a ação
        success : ( lista ) => { // caso sucesso
           var dias = $( '#Dia' ); //dropdown

           dias.empty(); //limpamos as options

           lista.each( (index, data) => { //foreach
              dias.append( '<option value="' + data + '">' + data + '</option>' ); //adicionamos uma option
           });
        }
      });
   })
})

</script>
    
17.02.2017 / 17:06
3

You can do this in two ways:

Adding the 31 days:

List<int> dias = new List<int>();

for (int i = 1; i <= 31; i++)
{
    dias.Add(i);
}

Adding the number of days of a specific month:

int qtdDias = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month);

for (int i = 1; i <= qtdDias; i++)
{
    dias.Add(i);
}

Then adding the text to the label in the selectionChanged event of the combobox:

lblDias.Content = cmbAging.SelectedValue;

Adding the list to the combo:

cmbDias.ItemsSource = dias;
    
17.02.2017 / 17:28
0

I ended up doing so, after investigating the net:

  if (string.IsNullOrEmpty(Request["idDiaAmortizacaoCredito"]))
  {
       List<clDays> d = new List<clDays>();
       foreach (int x in Enumerable.Range(1, 31).ToList())                    
           d.Add(new clDays() { day = x });                    
          LoadDropDownList(drpDay, "day", "day", () => d);

          this.lblDay.Visible = this.lblSourceID.Visible = false;
          this.drpDay.Visible = this.drpSourceID.Visible = true;
  }
    
17.02.2017 / 19:16
___ ___ verify erkimt registered user PHP Mysqli ______ qstntxt ___

Hello, I do not understand almost anything about Php and mysqli. I am trying to implement the system of users for the site, the registry is already working but I can register with the same email as many times as I want. How do I check if email already exists in BD?

So far I only have this, "index.php" form,

config.php (connects to the database);

controlindex.php (sending the values to the DB table)

%pre%     
______ azszpr166619 ___
%pre%     
______ azszpr166456 ___

Just check if a user already exists with the last email

%pre%

You should prevent SQL injection in your code, the way it is written SQL can be easily injected, has an explanation of how to prevent.

    

___ Split the database to multiple clients or create one for each? [closed]