display the sum of two datagrid columns into third column

hi... there..

    i have a datagrid with columns named Price ,Quantity and total. now in the total column i  wanna display the prices which comes by multiplyiing the price and quantity (like  total=Price * quantity). I'm workin in asp.net +vb.net.

                    may i knw hw can i do this.. plz write the code..

thanks.

       

0
saida
4/3/2009 10:30:17 AM
asp.net.client-side 24353 articles. 1 followers. Follow

6 Replies
4856 Views

Similar Articles

[PageSpeed] 56

Hi, do like this..

suppose u have,

        string ProductPrice = s[2].ToString();
         string Quantity = s[3].ToString();

now multiply,


string Total=ProductPrice * Quantity;

and put it in tht column.

 


Uthappa T.P
C# .Net
Visual Studio 2008
0
vinayuthappa
4/3/2009 10:51:34 AM

i assume that you've to do the calculation when you leave quantity textbox. override you grid rowdatabound event

protected gric_RowDataBound(........)

{

TextBox txtquant= e.Row.Cells[N].Controls[N] as TextBox;

TextBox txtprice= e.Row.Cells[N].Controls[N] as TextBox;

TextBox txttot= e.Row.Cells[N].Controls[N] as TextBox;

txtquant.Attributes.Add("onblur", string.Format("funCalculate('{0}','{1}')",txtprice.ClientID,txttot.ClientID )

}

now just define a javascritp function like this

function funCalculate(price,total)

{

document.getElementById(total).value = parseFloat(this.value) * parseFloat(document.getElementById(price).value)

}


SHASHANK BHIDE
CAPGEMINI INDIA
"THE ROAD TO SUCCESS IS ALWAYS UNDER CONSTRUCTION MARK MY RESPONSE AS ANSWER TO HELP ME BUILD IT :)"
0
shashankgwl
4/3/2009 10:55:31 AM
As you are taking the price and quantity from the database then you can use the following code to make your need.........................................





Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim _mainConnection As SqlConnection

        _mainConnection = New SqlConnection
        Dim _configReader As AppSettingsReader = New AppSettingsReader

        ' // Set connection string of the sqlconnection object
        _mainConnection.ConnectionString = _configReader.GetValue("Main.ConnectionString", "".GetType()).ToString()
       
        Dim dr As SqlDataReader
        Dim cmd As SqlCommand
        Dim dt As DataTable
        cmd = New SqlCommand("select id,qty,price,(qty*price) as total from tblPrice", _mainConnection)
        _mainConnection.Close()
        _mainConnection.Open()
        dr = cmd.ExecuteReader()
        DataGrid1.DataSource = dr
        DataGrid1.DataBind()
        _mainConnection.Close()
    End Sub
0
sajithms85
4/3/2009 11:34:26 AM

HI,

You can display total in third column using following expression :

(Convert.ToDecimal(Eval("Price").ToString()) * Convert.ToDecimal(Eval("Quantity").ToString()))

 


Always "Mark as Answer" the Post That Solves the problem.Because It helps others to find the solution.
Mohammad Hussain
http://mohdhussain.blogspot.com/
0
mohd786hussain
4/3/2009 11:59:44 AM

 hi..

  yes.. 'm fetching values from database but i don have one table. I am fetching values from 2  tables like my price is in product table and quantity is in order table .

   my query is  like this ..

    select (O.qty) as Quantity , (P.Price) as Price from Order O  inner join Product P  on O.Pid=P.PID

    nw  may i knw hw can i calculate the total and bind the value  to total column of datagrid.

0
saida
4/3/2009 12:38:17 PM

Hi,

try the following :

select (O.qty) as Quantity , (P.Price) as Price,(O.qty * P.price) as total from Order
O  inner join Product P  on O.Pid=P.PID


Always "Mark as Answer" the Post That Solves the problem.Because It helps others to find the solution.
Mohammad Hussain
http://mohdhussain.blogspot.com/
0
mohd786hussain
4/3/2009 12:45:07 PM
Reply:

Similar Artilces:

How to subtract two date columns(bound) of a Datagrid and display the result in the third column?
Hi Everyone,I  have two date columns(databound-coming from SQL database) in my datagrid, 'start date' & 'end date'. I need to calculate number of days with 'end date- start date' and display the result in the third datagrid column. i.e.: column2-column1 = column3Any help anyone?...ASAP please got a deadline to meet :) (SOS!!!)Many Thanks in advance,Arty.Aartee...we live more than once! Hi, there are several ways of doing it. One of them is creating a label in the TemplateColumn, use the Helper function to calculate the number of days.<ItemTemplate>   <...

How to subtract two numeric columns(bound) of a Datagrid and display the result in the third column?
Hi Everyone,I  have two numeric columns(databound-coming from SQL database) in my datagrid, 'PromoPrice' & 'CostPrice'. I need to calculate 'PromoPrice- CostPrice' and display the result in the third datagrid column. i.e.: column2-column1 = column3Any help anyone...Many Thanks in advance,Nico. In your query do this:Select .... , (PromoPrice - CostPrice) AS Answer, .....FROM yourTableKeep in mind you can do math functions in queries.DarmarkMark as Answer, if this reply answers your post. Hi Darmark, thanks for your fast answer.The fact is I'm using a single "select function" from webmatrix with one querie :Function MyQueryMethod() As System.Data.DataSet Dim connectionString As String = "server='prsasappweb'; user id=' '; password=' '; database='premier'" Dim dbConnection As System.Data.IDbConnection = New System.Data.SqlClient.SqlConnection(connectionString) Dim queryString As String = "SELECT [PromoConfig].* FROM [PromoConfig]" Dim dbCommand As System.Data.IDbCommand = New System.Data.SqlClient.SqlCommand dbCommand.CommandText = queryString dbCommand.Connection = dbConnection Dim dataAdapter As System.Data.IDbDataAdapter = New System.Data.SqlClient.SqlDataAdapter dataAdapter.SelectCommand = dbCommand Dim dataSet As System.Data.DataSet = New System.Data.DataSet dataAdapter.Fill(dataSet) Return dataSet End Function Sub Page_Load (sender As Object, e As EventArgs) DataGrid1.DataSource = MyQueryMethod() DataGrid1.DataBind()End Sub This is the code of my ...

Columns arrangement in DataGrid
Dear Friends, Please give me a solution for below problem, I have to bind a data table to a DataGrid, I will be not knowing no of columns and data until runtime, so I did not configured columns widh at design time. Now my client is asking me like, he want a facility to alter the column width at runtime, I mean he want to change columns width in client (IE), like window application. So, will you please tell me how to provide facility to change column width of a datagrid at client by user ? Thank you, Sreedhar Nasum.     Hi:   DataGrid will render as <table>. Ta...

How to display the sum of a column at the footor of the datagrid column
HI, Any idea how I can display the Sum of any column at the Footor of that Column. HighOnCodingWanna get high! Hi, Take a look @ Displaying Column Summary Information in the Footer HTH K B ShajudeenAreYaar.comDubai, United Arab Emirates....

column header to span two columns in a datagrid display
Is it possible for a column header to span two columns? If so how would this be done? Thanks In the ItemDataBound (or ItemCreated) check if Item is of type Header and if so - define the colspan property of the Cell object which you want to define the Colspan for and delete the next Cell from hte DataGridItem CheersBug [MCSD] Is it possible to span header column in design view only. using some kind of CSS. I'm using ASP,NET 3.5 and GridView...

Addition of two Columns in third Column.
Hi Guys, I got stucked in my project and i need your help. I have a data grid with data from sql 2005. I have got two amount columns - Amount1 & Amount2 with values from database. I want the addition of both in Total column (type: template) which I added in data grid view I also want the grand total of Total column in the bottom. Pls help  >I have got two amount columns - Amount1 & Amount2 with values from databaseWhy not change the select? ChangeSELECT  Amount1, Amount2 FROM FREDto SELECT  Amount1, Amount2, (Amount1 + Amount2) AS Amount3 FROM FRED...

Compare Two columns and update the Third Column
 Hi,I have three columns and want to update the third column based on the comparison of first two columns in the same table.For instance:Col1 - val1, val2, val3, val4, val5......Col2 - NULL, NULL, val1, NULL, val2....Col3 - TRUE, TRUE, FALSE, FALSE, FALSE....Thanks for any help. When you define a column, you can define it as a "computed column". Make col3 a computed column and fill in the comparison expression.    Dear David,Thanks for your reply. Actually I have table with more then 7000 records in it. and all the columns are already defined. I was lookin...

how to split the content of one column in the objectdatasource into two parts and let them display in two columns in the GridView?
i combine the title and the body of one article and store it in one column in the database,but i want to show the title and body seperately in the GridView,how should i achieve this goal?thank you so much for your advice!!! you can write the logic of splitting the column into two (title and body) in the query itself by which you are filling the datasource..Thanx, [KaushaL] || BloG || Profile || Microsoft MVP"I would love to change the world, but they won’t give me the source code"Don't forget to click "Mark as Answer" on the post that helped you.This credits that me...

Summing two columns in a datagrid
I am using the onitemdatabound property of the datagrid to sum two columns. The code i'm using is below. The CalcQuant and CalcSent calculate the totals by passing in the current rows value and adding it to the current total. But I get double the number in both rows. Why would these functions be getting called twice? Can anybody suggest an alternative or perhaps something I'm missing. Thanks public void closedlist_itemdatabound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) {...

Multiply two columns and store the result into third column
Hi,  I am new to asp.net world. I am having 1 problem in a gridview.   There are 3 template fields in my gridview namely Length , Width and Area. Length n Width contain textboxes and Area is having label. Problem is as soon as you enter the values in textboxes, the area should be calculated and reflected immediately in the area field of that row. I am using RowDataBound event gridview. But area is not getting update dynamically after changing the textfields.  Code i m using is: protected void gvArea_RowDataBound(object sender, GridViewRowEventArgs e)    {        if (e.Row.RowType == DataControlRowType.DataRow)        {            int length = Convert.ToInt32(((TextBox)e.Row.FindControl("txtLength")).Text);            int width = Convert.ToInt32(((TextBox)e.Row.FindControl("txtWidth")).Text);                        ((Label)e.Row.FindControl("lblArea")).Text = Convert.ToString(length * width);        }    } Hi GagaDCoder , GagaDCoder:Problem is as soon as you enter the values in textboxes, the area should be calculated and reflected immediat...

How to display column total of numeric columns in the datagrid footer
I able to connect Datagrid control to ADO.Net for pulling data. But I can not able to display total of a numeric field column in the Datagrid footer. Is it possible? How? Please tell me any one. Hi, please read up Displaying Column Summary Information in the Footer and HOW TO: Create a Summary Row for a DataGrid in ASP.NETHope this helps..Alvin ChooiMicrosoft ASP.NET™ Enthusiast v1.1 / v2.0, Malaysia Blog : http://alvinzc.blogspot.com...

two db table column, one datagrid column
Dear all, I have a db table which have two column, first name and last name. Can I show them in one datagrid column? Thanks Yes you may. Through the usage of the TemplateColumn, yes. An example of this: <code> <asp:DataGrid runat="server" ID="dgSomeGrid">     <Columns>         <asp:TemplateColumn>             <ItemTemplate>                 <%# DataBinder.Eval(Container.DataSource, "LastName") %&g...

double sum of two column in datagrid
hi, i have this function which return sum of column's items and put the total in footer: public void ComputeSum(object sender , DataGridItemEventArgs e) { if ((e.Item.ItemType == ListItemType.Item ) ||(e.Item.ItemType==ListItemType.AlternatingItem)) { int viewCount = Convert.ToInt32(DataBinder.Eval(e.Item.DataItem, "Credit")); viewCountSum += viewCount; } else if(e.Item.ItemType == ListItemType.Footer) e.Item.Cells[3].Text = "TotalCredit: "+ string.Format("{0:#,###}", viewCountSum); } on datagdrid : <...

hide datagrid columns client side
how to hide colums dynamicall (client side) not using serverside code....

How to Displaying the Sum of a Column in the Datagrid Footer
Hi all. Im need Displaying the Sum of a Column in the Datagrid Footer, but the property AutoGenerateColumns is True. ¿How to do This? Thanks to all. Mauricio Villagrán Try this: <asp:label id="lblClaimTotal" runat="server" ></asp:label> <asp:datagrid id="DataGrid1" runat="server" AllowPaging="False" DataKeyField="ID" OnItemDataBound="grid_ItemDataBound" > and in the code behind page 'Routine to highlight selected grid row. And to show total of claim amount colum...

When is a column not a column?
I have several extremely similar datawindows that I have to maintain that go against the same table. Recently, I had to add a column to that table, and also add the column to ALL of these datawindows that go against this table. I added the column to the first datawindow, set up the edit control style, etc. I then did a copy/paste of the columns edit control to the remaining dw's (of course remembering to first add the column in SQL). Everything (update props, column specs, column props) seems to indicate that the pasted column is linked to the column I selected, HOWEVER, when I...

Setting Datagrid Column to invisible when Column is an AutoGeneratedColumn NOT a bound Column
Hi all, Just like the title says, I'm trying to set a column to invisible but I'm unable to do so. If I bound the column I can used the code: me.datagrid.Column.Item(1).Visible = False But since I'm wanting the column NOT to be bound (there are a number of sql scripts that populate the same datagrid so I cannot bound all the columns since the columns are different for each script etc etc etc) how do I set an AutoGeneratedColumn to invisible?? Please help! Andrewwww.codingmayhem.com - VB.NET, C#, Silverlight, Javascript, HTML, CSS, T-SQL, MySQL and SQLitewww.headshot...

how to pull several columns info from db then display them as one column in datagrid?
I have difficulty to gether several columns info from db to display them as one column in datagrid. say I have a table which has columns: "name", "street", "address", "city", "state", "zip", "status", Ex: I want to pull "street address", "city", "State", and "zip" from that table then diaplay them as one column "Address" in the datagrid so that the datagrid will only have 3 columns to display --"Name", "Address" and "Status". How do I do it...

Datagrid checkbox column client side validation
Hi, i have a datagrid with a checkbox column. I want to restrict on the client the number of rows (checkboxes) selected. Is there any way to count user selected checkboxes without going to the server? And another question: is it possible to have external css file with datagrid attributes, such as itemstyle colors, alternatingitemstyle, paging, etc. Thanks George I'm pretty sure you could do this client side. Maybe iterate through the controls on within the form, checking for the type of the control. The code below should get you started, but it's not the total solution by any me...

display XML data in datagrid with checkbox column <template column>
i can set the datagrid.datasource = myXmlDataset, but anyone know how i can hook an unbound column (template column with a checkbox) to one of my XML fields ??? i was thinking of creating a datatable from scratch, cycling thru the items in the XML document and wring them into the table, then filling myXmlDataset, then binding that dataset to my datagrid. but this has proved to be more of a challenge than i thought. anyone tried doing this before ??? is it even feasible ???"If it is secrect enough, you alone know it." I might be missing something but why don't you read you...

Column within a column in a DataGrid
Hi, I have a DataGrid on which I would like to divide a particular column into 2 to display a number information on the sub column?? Visually I'm speaking something like this below. +----------------+-----------------+ | ACCOUNTID | ACCOUNT NO | +----------------+-----------------+ | 1000 | | 125364 | | 1015 | | 125365 | | 1025 | | 125312 | +-----------------+----------------+ My question again is how to see this extra sub column within the ACCOUNTID Column here. Looking for a quick reply. Th...

GridView / DataGrid with Side by Side Columns
Ok, that certainly wasn't the best way to describe what I'm trying to do, but basically think of a datagrid/gridview reading like a newspaper where the datarows go down, then continue after x number of rows to the top of the 2nd column and then down again.Is this possible?  And if it's easier to just do data_column1 ==> data_column2, next row, data_column1 ==> data_column2, next row, etc.Thanks so much!!!...

Displaying two rows of database column data in one row of datagrid
Hello, I am trying to display two rows of an access column on one row of datagrid. Is that possible? Example of my intended datagrid: courseNo of course1courseNo of course2 courseNo of course3courseNo of course4 here's the HTML view of my aspx file: <Asp:datagrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 104px; POSITION: absolute; TOP: 40px"    runat="server" AutoGenerateColumns="False" Height="320px" Width="488px">    <Columns>     <asp:TemplateColumn>      &...

Display Multiple Columns into One Column
My first ASP.NET/SQL project. I'm creating an Asset Management DB. I wish to view the Asset number, the full name of the user it's assigned to and the Make and Model of each record in the DB. However assets are split into different categories e.g. monitors, PCs, Preinters etc. and they are all in different tables. The SQL below displays the asset number, Name of person assigned and the model of the asset. SELECT Hardware.AssetNo, [User].FullName, MonitorModel.Model, PCModel.Model AS Expr1, PrinterModel.Model AS Expr2 FROM Hardware INNER JOIN [User] ON Hardware.UserID = [User].User...

Web resources about - display the sum of two datagrid columns into third column - asp.net.client-side

Want to preview our new DataGrid for Xamarin.Forms?
tl;dr Zumero.DataGrid is a Xamarin.Forms control for displaying data in rows and columns. If you would be interested in testing and previewing ...

Mad King DataGrid
This post is about scrolling in WPF and the egocentric DataGrid control. I’ll give the project background but if all you’re interested in is ...

Stack Overflow
Stack Exchange log in - careers - chat - meta - about - faq Questions Tags Users Badges Unanswered Ask Question Top Questions interesting 295 ...

Microsoft Silverlight - Wikipedia, the free encyclopedia
Microsoft Silverlight is an application framework for writing and running rich Internet applications , with features and purposes similar to ...

Flash Builder Plug-in for SAP Netweaver Gateway - Adobe Labs
Search Navigation Labs Home Wiki Home Technologies Alchemy Blueprint Camera Profiles and DNG Profile Editor Cirrus ColdFusion 10 DNG Codec Fireworks ...

Casaba Security » Products » X5s Testing Tool For Finding XSS Vulnerabilities
Security analysis, consulting, development and testing partners who understand your business strategy.

CodeGuru - Microsoft developers related ideas, articles, tips, tricks, comments, downloads, and so much ...
CodeGuru is where developers can come to share ideas, articles, questions, answers, tips, tricks, comments, downloads, and so much more related ...

Caliburn Micro: WPF, Silverlight, WP7 and WinRT/Metro made easy.
A small, yet powerful framework designed for WPF, Silverlight and WP7. It implements a variety of UI patterns for solving real-world problems. ...

Quick Answers - CodeProject
Questions - Free source code and tutorials for Software developers and Architects.; Updated: 11 Jul 2012

license-discuss@opensource.org: 11636: first draft of license proliferation committee report
FYI,the first draft report of the OSI's License Proliferation Committee.To join the OSI's license proliferation discuss email list, send anemail ...

Resources last updated: 3/9/2016 4:45:10 AM