?
Solved

code behind c#.

Posted on 2015-02-06
11
Medium Priority
?
138 Views
Last Modified: 2015-03-12
I have below asp.net webform and I want to do below math, and I want to do it dynamic in code behind/c#?
Is it possible?



listPrice01 = model01(array[2])
extnPrice01 = qty * UnitPrice
unitPrice01 = listPrice01 * listPrice01 * priceType01

Get the total of each column:

totalListPrice
totalUnitPrice
totalExtnPrice


<table width="1024" cellpadding="3" cellspacing="3">
<tr><td>Action</td><td>Model</td><td>Qty</td><td>Price Type</td><td>List Price</td><td>Unit Price</td><td>Extn Price</td></tr>
<tr>
<td><asp:Button runat="server" ID="btnRemove"  Text="Remove" /></td>
<td><asp:DropDownList runat="server" ID="model01">
<asp:ListItem Text="ModelNo,ModelDescrption,1000" Value="ModelNo,ModelDescription,1000"></asp:ListItem>
<asp:ListItem Text="ModelNo,ModelDescrption,2000" Value="ModelNo,ModelDescription,2000"></asp:ListItem>
</asp:DropDownList></td>
<td><asp:TextBox runat="server" ID="Qty01"></asp:TextBox></td>
<td><asp:DropDownList runat="server" ID="priceType01">
<asp:ListItem Text="0.08" Value="0.08"></asp:ListItem>
<asp:ListItem Text="0.10" Value="0.10"></asp:ListItem>
<asp:ListItem Text="0.12" Value="0.12"></asp:ListItem>
<asp:ListItem Text="0.13" Value="0.13"></asp:ListItem>
</asp:DropDownList></td>
<td><asp:Label runat="server" ID="listPrice01" Text="0.00"></asp:Label></td>
<td><asp:TextBox runat="server" ID="unitPrice01"></asp:TextBox></td>
<td><asp:Label runat="server" ID="extnPrice01" Text="0.00"></asp:Label></td>
</tr>
<tr>
<td><asp:Button runat="server" ID="Button1"  Text="Remove" /></td>
<td><asp:DropDownList runat="server" ID="model02">
<asp:ListItem Text="ModelNo,ModelDescrption,1000" Value="ModelNo,ModelDescription,1000"></asp:ListItem>
<asp:ListItem Text="ModelNo,ModelDescrption,2000" Value="ModelNo,ModelDescription,2000"></asp:ListItem>
</asp:DropDownList></td>
<td><asp:TextBox runat="server" ID="Qty02"></asp:TextBox></td>
<td><asp:DropDownList runat="server" ID="priceType02">
<asp:ListItem Text="0.08" Value="0.08"></asp:ListItem>
<asp:ListItem Text="0.10" Value="0.10"></asp:ListItem>
<asp:ListItem Text="0.12" Value="0.12"></asp:ListItem>
<asp:ListItem Text="0.13" Value="0.13"></asp:ListItem>
</asp:DropDownList></td>
<td><asp:Label runat="server" ID="listPrice02" Text="0.00"></asp:Label></td>
<td><asp:TextBox runat="server" ID="unitPrice02"></asp:TextBox></td>
<td><asp:Label runat="server" ID="extnPrice02" Text="0.00"></asp:Label></td>
</tr>
 
<tr bgcolor="silver">
<td colspan="2"><br /></td><td><asp:Label runat="server" ID="totalQty"></asp:Label></td>
<td><br /></td>
<td><asp:Label runat="server" ID="totalListPrice"></asp:Label></td>
<td><asp:Label runat="server" ID="totalUnitPrice"></asp:Label></td>
<td><asp:Label runat="server" ID="totalExtnPrice"></asp:Label></td>
</tr>
</table>
0
Comment
Question by:ITsolutionWizard
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 2
11 Comments
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 40594936
In:
extnPrice01 = qty * UnitPrice
unitPrice01 = listPrice01 * listPrice01 * priceType01

Where is UnitPrice? Is it related to unitPrice01?

Has UnitPrice typo? I cannot find it in your .aspx source file.

Also, you have Qty01 but not qty; are they the same?
0
 
LVL 1

Author Comment

by:ITsolutionWizard
ID: 40594955
listPrice01 = model01(array[2])
extnPrice01 = qty01 * UnitPrice01
unitPrice01 = listPrice01 * listPrice01 * priceType01

Sorry above should be logical
0
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 40594961
Do you have some code in code behind or it is blank?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 34

Accepted Solution

by:
Mike Eghtebas earned 2000 total points
ID: 40595123
1. Locate the following line and add the portion in bold font:

<td><asp:DropDownList runat="server" ID="model01" bordercolor="yellow" AutoPostBack="true" OnSelectedIndexChanged="model01_SelectedIndexChanged">

2. Double click on model01 dropbox in design view. This gives you:

  protected void model01_SelectedIndexChanged(object sender, EventArgs e)
    {
        listPrice01.Text = model01.Text;    //<-- add this line
    }

Open in new window


3. run the page and select "ModelNo,ModelDescription,1000" option for example. This string will show up in ListPrice01 text box.

For now focusing on the first formula:

listPrice01 = model01

listPrice01 noe contains string "ModelNo,ModelDescription,1000". Because its content will be used later in the third formula, we will have problems with it. For listPrice01 we need to have just a number. Where this number is supposed to be coming?
0
 
LVL 1

Author Comment

by:ITsolutionWizard
ID: 40595149
if we use autopostback = true, alot of data will be gone. Is it possible not to use it?
another problem is because I will have more than 2 row meaning more than 2 model drop down.
so I have to create selectedindexchange many more. is it possible to have something dynamic?

Thanks
0
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 40595250
we can remove autopostback = true. Instead use a submit button with autopostback = true to click when ready.
0
 
LVL 23

Expert Comment

by:Snarf0001
ID: 40596178
Just to throw my 2 cents in here, why do you want to do this in code-behind?
That's a horrid user experience.  Every time the user changes something the page would submit and refresh for them, causing needless postbacks to the server.
You could get around the page refresh with ajax, but you're still sending very pointless trips to the server to do a calculation that would be very simple to do on client side javascript.

Is there any specific reason you want to do it server-side?
0
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 40596218
As far as I know, which is not much, having asp in your ,aspx file gets server involved one way or another. Now it becomes the choice of where to maintain the code you want to write. Some people like to combine it with their .aspx codes but you specifically have asked for code behind c#. It happens I also prefer to keep them, separately. What I have giving is code behind.

<td><asp:Button runat="server" ID="btnRemove"  Text="Remove" /></td>

Question: Where is your data source. Do you want these just for display (like a calculator) only? Or, you would want to save them in some database?

Mike
0
 
LVL 23

Expert Comment

by:Snarf0001
ID: 40596242
Well yes and no.  Having the asp: prefix on the input items means the server is tracking it through postbacks and viewstate, but you still have full availability to access everything client side.

And I do realize you're answering the question asked, I'm just saying overall it's very much not the best way to approach it.
Any changes made to the input fields through js will still post back to the server with their current values, if and when the entire page is submitted, and can still save or do whatever the server process is.

But for simple addition / sum calculations like requested, the overhead on both the server and the client is very unnecessary.

A few lines of javascript executing on the client, vs an entire ajax (or full postback) on the client, and another entire request cycle on the server.
0
 
LVL 23

Expert Comment

by:Snarf0001
ID: 40596245
FYI, eghtebas, re-reading my last comment, could have come across as somewhat snotty.
If it did, wasn't intended that way at all ;)
0
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 40596276
We are at EE to learn. Nothing else really matters. As far as I am concern is to pay attention to the solution sought and help out as much as I can and then also learn in the process.

BTW, you didn't answer my question on what do you do with the data produced in this project. Or. whom this project serves and how it is intended to do that.

Mike
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question