////CODIGO ASP.NET (HTML)
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="DropDownList.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div>
<asp:DropDownList ID="DropDownList1" AutoPostBack="true" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Value="0">--seleccione--</asp:ListItem>
<asp:ListItem Value="1">Alejandro Fernández</asp:ListItem>
<asp:ListItem Value="1">Justin Timberlake</asp:ListItem>
<asp:ListItem Value="1">Justin Beber</asp:ListItem>
<asp:ListItem Value="1">Usher</asp:ListItem>
<asp:ListItem Value="2">Pedrito Fernández</asp:ListItem>
<asp:ListItem Value="3">Alejandro Zans</asp:ListItem>
<asp:ListItem Value="3">Paulina Rubio</asp:ListItem>
<asp:ListItem Value="3">Jenifer López</asp:ListItem>
<asp:ListItem Value="3">Madonna</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" AutoPostBack="true" runat="server" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged">
<asp:ListItem Value="1">Europeo</asp:ListItem>
<asp:ListItem Value="2">Centro Américano</asp:ListItem>
<asp:ListItem Value="3">Aisiatico</asp:ListItem>
<asp:ListItem Value="4">Sur Américano</asp:ListItem>
<asp:ListItem Value="5">Caribeño</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="DropDownList3" AutoPostBack="true" runat="server" OnSelectedIndexChanged="DropDownList3_SelectedIndexChanged">
<asp:ListItem Value="1">Pop</asp:ListItem>
<asp:ListItem Value="2">Rock</asp:ListItem>
<asp:ListItem Value="2">Ranchera</asp:ListItem>
<asp:ListItem Value="2">Romántico</asp:ListItem>
</asp:DropDownList>
</div>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress runat="server" AssociatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate>
<div>Procesando....</div>
</ProgressTemplate>
</asp:UpdateProgress>
<asp:Button ID="Button1" runat="server" Text="insertar en tabla" OnClick="Button1_Click" />
</form>
</body>
</html>
///////CODIGO ASP.NET (C#)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace DropDownList
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
//con esto no se pierde el valor de las variables en el entorno de navegacion, es un poco antiguo el metodo pero funciona
Artista = DropDownList1.SelectedItem.Text;
VArtista = Convert.ToInt32(DropDownList1.SelectedItem.Value);
Procedencia = DropDownList2.SelectedItem.Text;
VProcedencia = Convert.ToInt32(DropDownList2.SelectedItem.Value);
Genero = DropDownList3.SelectedItem.Text;
VGenero = Convert.ToInt32(DropDownList3.SelectedItem.Value);
}
}
//Estos son medotos auxiliares que te permitiran fijar las propiedades en el entorno
private string _artista;
private int _vartista;
public string Artista
{
set { _artista = value; }
get { return _artista; }
}
public int VArtista
{
set { _vartista = value; }
get { return _vartista; }
}
private string _procedencia;
private int _vprocedencia;
public string Procedencia
{
set { _procedencia = value; }
get { return _procedencia; }
}
public int VProcedencia
{
set { _vprocedencia = value; }
get { return _vprocedencia; }
}
private string _genero;
private int _vgenero;
public string Genero
{
set { _genero = value; }
get { return _genero; }
}
public int VGenero
{
set { _vgenero = value; }
get { return _vgenero; }
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
Artista = DropDownList1.SelectedItem.Text;
VArtista = Convert.ToInt32(DropDownList1.SelectedItem.Value);
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
Procedencia = DropDownList2.SelectedItem.Text;
VProcedencia = Convert.ToInt32(DropDownList2.SelectedItem.Value);
}
protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
{
Genero = DropDownList3.SelectedItem.Text;
VGenero = Convert.ToInt32(DropDownList3.SelectedItem.Value);
}
protected void Button1_Click(object sender, EventArgs e)
{
InsertarTabla(Artista, VArtista, Procedencia, VProcedencia, Genero, VGenero);
}
protected void InsertarTabla(string _artista, int _vartista, string _prosedencia, int _vprosedencia, string _genero, int _vgenero)
{
string mesg = String.Format("Se insertará el Artista {0} con el valor {1} de procedencia {2} con valor de procedencia {3} y con el genero {4} de valor {5}", _artista, _vartista, _procedencia, _vprocedencia, _genero, _vgenero);
Response.Write(mesg);
}
}
}