Click here to Skip to main content
15,889,266 members
Home / Discussions / C#
   

C#

 
GeneralRe: socket problem: works in visual studio, not as release Pin
Luc Pattyn1-Oct-09 7:09
sitebuilderLuc Pattyn1-Oct-09 7:09 
General[SOLVED] Re: socket problem: works in visual studio, not as release Pin
TimWallace1-Oct-09 8:34
TimWallace1-Oct-09 8:34 
GeneralRe: [SOLVED] Re: socket problem: works in visual studio, not as release Pin
Luc Pattyn1-Oct-09 8:41
sitebuilderLuc Pattyn1-Oct-09 8:41 
QuestionMethod not calculating properly‏ Pin
Marcus Farrugia1-Oct-09 5:09
Marcus Farrugia1-Oct-09 5:09 
AnswerRe: Method not calculating properly‏ [modified] Pin
harold aptroot1-Oct-09 5:22
harold aptroot1-Oct-09 5:22 
GeneralRe: Method not calculating properly‏ Pin
PIEBALDconsult1-Oct-09 15:31
mvePIEBALDconsult1-Oct-09 15:31 
AnswerRe: Method not calculating properly‏ Pin
Luc Pattyn1-Oct-09 5:34
sitebuilderLuc Pattyn1-Oct-09 5:34 
AnswerRe: Method not calculating properly‏ Pin
J4amieC1-Oct-09 6:32
J4amieC1-Oct-09 6:32 
Well your code is a bit of a mess. As Luc has pointed out, ASP.NET will reset each of those class variables to zero on postback. There is the option of persisting values between postbacks but a more elegant solution would be to calculate the price whenever you need it.

I would approach this as follows, start with a method to do the actual proce calculation

private decimal CalculatePrice()
{
  decimal sizePrice = 0;
  switch(rblSize.SelectedValue)
  {
    case "Slice": sizePrice = 8;break;
    case "Small": sizePrice = 10;break;
    // -- etc.
  }

  decimal ingredientsPrice = 0;
  for (int i = 0; i < cblIngredients.Items.Count; i++)
  {
    if (cblIngredients.Items[i].Selected)
    {
      ingredientsPrice ++;
    }
  }

  return sizePrice + ingredientsPrice ;
}


Next have this method called when either action is performed

protected void RadioButtonList1_SelectedIndexChanged1(object sender, EventArgs e)
{
  decimal totalPrice = CalculatePrice();
  lblPriceTotal.Text = totalPrice.ToString();
)

protected void cblIngredients_SelectedIndexChanged(object sender, EventArgs e)
{
  decimal totalPrice = CalculatePrice();
  lblPriceTotal.Text = totalPrice.ToString();
}

AnswerRe: Method not calculating properly‏ Pin
Keith Barrow1-Oct-09 7:05
professionalKeith Barrow1-Oct-09 7:05 
QuestionUploading pictures. Pin
Mix Wheels1-Oct-09 4:17
Mix Wheels1-Oct-09 4:17 
AnswerRe: Uploading pictures. Pin
Luc Pattyn1-Oct-09 4:22
sitebuilderLuc Pattyn1-Oct-09 4:22 
QuestionSearching a non-PrimaryKey column within a DataTable with a partial string. Pin
KCI-VA1-Oct-09 3:49
KCI-VA1-Oct-09 3:49 
AnswerRe: Searching a non-PrimaryKey column within a DataTable with a partial string. Pin
Eddy Vluggen1-Oct-09 10:16
professionalEddy Vluggen1-Oct-09 10:16 
QuestionRe: Searching a non-PrimaryKey column within a DataTable with a partial string. Pin
KCI-VA1-Oct-09 10:37
KCI-VA1-Oct-09 10:37 
AnswerRe: Searching a non-PrimaryKey column within a DataTable with a partial string. Pin
KCI-VA8-Oct-09 5:32
KCI-VA8-Oct-09 5:32 
QuestionWindows Forms: TreeView in SplitContainer flickers on Resizing the screen ar runtime Pin
Poornima Naik1-Oct-09 3:21
Poornima Naik1-Oct-09 3:21 
QuestionRemove program from Control panel using C# Pin
Ajithevn1-Oct-09 3:07
Ajithevn1-Oct-09 3:07 
AnswerRe: Remove program from Control panel using C# Pin
stancrm1-Oct-09 3:18
stancrm1-Oct-09 3:18 
QuestionRe: Remove program from Control panel using C# Pin
Eddy Vluggen1-Oct-09 3:48
professionalEddy Vluggen1-Oct-09 3:48 
AnswerRe: Remove program from Control panel using C# Pin
Ajithevn1-Oct-09 6:07
Ajithevn1-Oct-09 6:07 
GeneralRe: Remove program from Control panel using C# Pin
Eddy Vluggen1-Oct-09 10:07
professionalEddy Vluggen1-Oct-09 10:07 
QuestionBuild issue [modified] : SOLVED Pin
Mustafa Ismail Mustafa1-Oct-09 2:54
Mustafa Ismail Mustafa1-Oct-09 2:54 
AnswerRe: Build issue Pin
Vasudevan Deepak Kumar1-Oct-09 3:01
Vasudevan Deepak Kumar1-Oct-09 3:01 
GeneralRe: Build issue Pin
Mustafa Ismail Mustafa1-Oct-09 3:52
Mustafa Ismail Mustafa1-Oct-09 3:52 
AnswerRe: Build issue Pin
Keith Barrow1-Oct-09 3:05
professionalKeith Barrow1-Oct-09 3:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.