I'm new to developing ASP.NET with C #, and I have the following question:
When loading a page, I run a method that populates a DropDownList. This DropDownList is part of a form and after it is filled out and the user clicks on the "Include" button, the Include () method will be triggered.
My intent is to get the Index of the selected DDL option because, based on this number, I get the ID that was stored while loading the page in a List
See the code:
List<String> _Processos = new List<String>();
List<String> _Unidades = new List<String>();
protected bool Incluir()
{
bool r = false;
System.Windows.Forms.MessageBox.Show(cbUnidadeIncidente.SelectedIndex.ToString());
OC o = new OC();
o.IdUsuario = (String)Session["IDUsuario"];
o.Dt = DateTime.Parse(txtDtOcorrencia.Text);
o.Descricao = Kompaktor.K.KSTR(txtDescricao.Text);
o.UnidadeIncidente = _Unidades[cbUnidadeIncidente.SelectedIndex];
o.UnidadeAfetada = _Unidades[cbUnidadeAfetada.SelectedIndex];
o.Observacao = txtObservacao.Text;
o.Processo = _Processos[cbProcesso.SelectedIndex];
o.Perda = Kompaktor.K.KSTR(txtPerda.Text);
o.Solucao = Kompaktor.K.KSTR(txtSolucao.Text);
o.Incluir();
return r;
}
However, during execution, just the first line that tries to do the procedure of trying to get the Index triggers an error, saying that the value of the vector of the list has been exceeded.
I already know that the problem is in List < & gt ;, after all, using a messagebox, the value of the sealing is shown. Lists appear to be zeroed when loading. And now, how can I proceed (so that these lists are visible throughout the class)?
Thanks in advance!