Reputation: 2823
OK, so I have a column in MYSQL data base, the column called specie
in there I have dog,cat,and rabbit.
I then have a drop down list that is populated with the data from specie
. I need a switch statement
that will display a Label
for each pet selected.
e.g. if user selects rabbit, the rabbit cost £00.00
here is my code for the drop down list
public partial class _Default : Page
{
DataSet ds = new DataSet();
MySqlConnection cs = new MySqlConnection(@"SERVER= 000.000.00.000;username=*****;password=*****; Initial Catalog = mydb");
MySqlDataAdapter da = new MySqlDataAdapter();
protected void Page_Load(object sender, EventArgs e)
{
MySqlCommand cd = new MySqlCommand("SELECT * FROM pets", cs);
cs.Open();
MySqlDataReader ddl = cd.ExecuteReader();
DdPetPist.DataSource = ddl;
DdPetPist.DataValueField = "Specie";
DdPetPist.DataTextField = "Specie";
DdPetPist.DataBind();
cs.Close();
cs.Dispose();
}
Upvotes: 0
Views: 131
Reputation: 339
I am assuming you have the cost of each animal stored in the database as well. If so, here is how I would do this:
Makes sense?
Upvotes: 1