1) On the page_load event, Bind the dropdownlist to a database using
SqlConnection conn = new SqlConnection("blablabla");
SqlDataAdapter ddAdapter = new SqlDataAdapter("SELECT * FROM products", conn);
DataSet ds = new DataSet();
ddAdapter.Fill(ds);
2) On the DropDownList1_selectedIndexChanged,
- When user select a value (the productName) from the dropdownlist
- All the database value will load on their specific labels (label1, label2)
- When user clicks the button (button1), it'll calculate total amount of already selected items' value and display on same label (label1, label2)
productID productName productPrice(label1) productBalance(label2)
1Car 2.3 400
2 Pencil Null 33
3 Eraser 22 0
SqlCommand cmd = new SqlCommand("SELECT * FROM products WHERE productID = @id", conn);
cmd.Parameters.AddWithValue("@id", myValue);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
Label1ext = dr["productPrice"].ToString();
Label2.Text = dr["productBalance"].ToString();
}
//TO COUNT TOTAL
//totalNum needs to be the number of items that were selected on DropDownList1
int i = 0;
int totalNum = 0;
while (i <= totalNum)
{
}
So if user's first selection is "Car" on the dropdownlist and the second selection is "Eraser",
when the button is clicked it'll calculate 2.3 + 22 for label1 and 400 + 0 for label2 and display.
I have googled search for solutions but I'm not so sure if it works right. Can someone lend me a helping hand? Am I anywhere near it or totally wrong lmao