Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

492
Views
Cómo obtener el valor seleccionado de la lista desplegable C# ASP.NET

he creado un sitio web simple formulario web asp.net usando C #. tengo un código para mostrar datos en la lista desplegable cuando la página se carga así:

 private void DisplayData() { List<ListItem> items = new List<ListItem>(); items.Add(new ListItem("User", "1")); items.Add(new ListItem("Administrator", "0")); DropdownList1.DataSource = items; DropdownList1.DataBind(); }

Lo llamo en la carga de la página:

 protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { DisplayData() } }

trato de obtener valor de DropdownList1 en btnSubmit

 protected void btnSubmit_Click(object sender, EventArgs e) { lblResult.Text = DropdownList1.SelectedValue; }

este resultado siempre obtiene el valor de la cadena User o Administartor . pero, no quiero. Quiero obtener valor solo de los valores en DropdownList1 como 0 o 1 . ¿Como hacer esto?

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Un enfoque es usar la propiedad DropDownList SelectedItem para obtener el elemento seleccionado ( ListItem ) y luego usar la propiedad ListItem.Value para obtener el valor correspondiente para ListItem .

 lblResult.Text = DropdownList1.SelectedItem.Value; // Value property Gets or sets the value associated with the ListItem.
about 4 years ago · Santiago Trujillo Report

0

Intente especificar DataValueField de DropDownList1:

 DropdownList1.DataSource = items; DropdownList1.DataValueField = "Value"; DropdownList1.DataTextField = "Text"; DropdownList1.DataBind();
about 4 years ago · Santiago Trujillo Report

0

Convert.ToInt32(DropdownList1.selectedItem.value);
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!