Когда выбран пункт checkboxlist1
, функция не будет вызвана !!!!Функция Asp.net не получает вызов
Я пытаюсь вызвать функцию вычисления стоимости, когда что-либо выбирается из флажка и выпадающего списка. Пожалуйста, укажите на ошибки в этом коде, почему это не работает. Я использую версию Visual Studio 2013.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Lab8_1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Session["Variable1"] = TextBox1.Text;
//Label1.Text = Session["Variable1"].ToString();
Response.Redirect("Lab8_2.aspx");
}
protected void Button2_Click(object sender, EventArgs e)
{
Session["Total"] = Total.Text;
Total.Text = Session["Total"].ToString();
Response.Redirect("Lab8_2.aspx");
}
protected void CheckboxList1_SelectedValueChanged(object sender, EventArgs e)
{
Compute_Item_Cost();
}
protected void Compute_Item_Cost()
{
Session["Total"] = 0;
Session["Cart"] = "";
foreach (ListItem listItem in CheckBoxList1.Items)
{
if (listItem.Selected)
{
switch(listItem.Text)
{
case "Wilson":
Session["Total"] = Convert.ToDecimal(Session["Total"]) + (Convert.ToDecimal(listItem.Value)*(Convert.ToInt32(DropDownList1.SelectedValue)));
break;
case "Slazenger":
Session["Total"] = Convert.ToDecimal(Session["Total"]) + (Convert.ToDecimal(listItem.Value)*(Convert.ToInt32(DropDownList2.SelectedValue)));
break;
case "Babolai":
Session["Total"] = Convert.ToDecimal(Session["Total"]) + (Convert.ToDecimal(listItem.Value)*(Convert.ToInt32(DropDownList3.SelectedValue)));
break;
case "Ihead":
Session["Total"] = Convert.ToDecimal(Session["Total"]) + (Convert.ToDecimal(listItem.Value)*(Convert.ToInt32(DropDownList4.SelectedValue)));
break;
case "Prince":
Session["Total"] = Convert.ToDecimal(Session["Total"]) + (Convert.ToDecimal(listItem.Value)*(Convert.ToInt32(DropDownList5.SelectedValue)));
break;
}
Total.Text = Session["Total"].ToString();
}
}
}
}
Вот код ASPX
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Lab8_1.aspx.cs" Inherits="Lab8_1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" Runat="Server">
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<br />
<br />
<br />
<table style="width: 100%">
<tr>
<td>
<asp:CheckBoxList ID="CheckBoxList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="CheckboxList1_SelectedValueChanged">
<asp:ListItem Value="10">Wilson</asp:ListItem>
<asp:ListItem Value="8">Slazenger</asp:ListItem>
<asp:ListItem Value="6">Babolai</asp:ListItem>
<asp:ListItem Value="12">Ihead</asp:ListItem>
<asp:ListItem Value="10">Prince</asp:ListItem>
</asp:CheckBoxList>
</td>
<td>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
<br />
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True">
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
<br />
<asp:DropDownList ID="DropDownList3" runat="server" AutoPostBack="True">
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
<br />
<asp:DropDownList ID="DropDownList4" runat="server">
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
<br />
<asp:DropDownList ID="DropDownList5" runat="server" AutoPostBack="True">
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
</table>
<br />
<asp:Label ID="Total" runat="server" Text="Label"></asp:Label>
<br />
Получение FormatException из String["Total"]
линий .... внутри сазе
ли вы подключить его к выбору изменено событие в ASPX? Можете ли вы добавить код aspx? – kmcnamee
<% @ Название страницы = "" Язык = "C#" MasterPageFile = "~/Site.master" AutoEventWireup = "true" CodeFile = "Lab8_1.aspx.cs" Inherits = "Lab8_1"%> asp: TextBox> –
пытается добавить код aspx, но не может это сделать здесь .... –