ASP.NET C# ändern ausgewählter Wert aus drop-down-Liste Ausgabe label

Ok also das problem, das ich habe, ist mit einem drop-down-Liste.
die drop-down-Liste soll-Ausgang (Drinklabel) der gewählte Wert, es Dosis dieses aber nur der erste in der Liste (drop-down-Liste generiert wird, die von session-variable).

Ich würde es gerne, so konnte ich mithilfe der drop-down-Liste, wählen Sie neuen Wert haben dann die Bezeichnung (Drinklabel) selbst aktualisieren.

*code Balg *

 protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        Drinklabel.Text = "Your Chosen Beverage is A " + DropDownList1.SelectedValue.ToString() + " Drink.";
    }

////////////////////////////////////////////////////////////

Voll über die Seite code

public partial class About : Page
{
    protected void Page_Load(object sender, EventArgs e)
    {


        MyFruit = Session["Fruitname"] as List<string>;
        //Create new, if null
        if (MyFruit == null)
            MyFruit = new List<string>();
        DropDownList1.DataSource = MyFruit;
        DropDownList1.DataBind();

    }

    public List<string> MyFruit { get; set; }

    protected void ButtonCalculate_Click(object sender, EventArgs e)
    {
        decimal total = calculatePrice(DropDownList1.SelectedItem.Text,
                                       TextBoxQuantity.Text.Trim());

        LabelResult.Text = "You would like " + TextBoxQuantity.Text.Trim() +
            DropDownList1.SelectedItem.Text + "(s) for a total of $" +
            total.ToString();
    }

    private decimal calculatePrice(string p1, string p2)
    {
        throw new NotImplementedException();
    }

    private decimal calculatePrice(string fruitName, int quantity)
    {
        //Ask the database for the price of this particular piece of fruit by name
        decimal costEach = GoToDatabaseAndGetPriceOfFruitByName(fruitName);

        return costEach * quantity;
    }

    private decimal GoToDatabaseAndGetPriceOfFruitByName(string fruitName)
    {
        throw new NotImplementedException();
    }


}
  • könnten Sie bitte zeigen Sie uns den code, wie Sie beim binden der session-Daten in DropDownList
  • ok oben gepostet, danke
  • könnten Sie bitte prüfen, ob-Sitzung gültige Daten enthält oder nicht?
InformationsquelleAutor Beep | 2013-11-10
Schreibe einen Kommentar