473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Simple Math in Gridview

Newbie here trying to learn.

Using VS2005 / learning in VB.NET for an ASPX page.

Sorry for this simple question. I have a Gridview1 with 2 columns. I added
a 3rd column and all I want to do is add the numbers in the 1st and 2nd
column together for the 3rd column. Can someone tell me where I can put the
code in Visual Studio 2005 and how I tell the Gridview to do the simple
math?

Is there a site that will teach me exactly this? I googled but didn't find
exactly this.
Sep 22 '06 #1
1 2105
Hi,
Here is a simple way to do what you are looking for
<script runat="server">
void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.Add("FirstColumn",typeof(int));
dt.Columns.Add("SecondColumn", typeof(int));
DataRow dr = dt.NewRow();
dr["FirstColumn"]=34;
dr["SecondColumn"]=12;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["FirstColumn"]=7;
dr["SecondColumn"]=4;
dt.Rows.Add(dr);

grd.DataSource=dt;
grd.DataBind();
}
}

</script>
<asp:GridView runat="server" ID="grd" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="FirstColumn" HeaderText="First" />
<asp:BoundField DataField="SecondColumn" HeaderText="Second"
/>
<asp:TemplateField HeaderText="Sum">
<ItemTemplate>
<%# ((int)Eval("FirstColumn"))
+((int)Eval("SecondColumn")) %>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
"Phillip Vong" wrote:
Newbie here trying to learn.

Using VS2005 / learning in VB.NET for an ASPX page.

Sorry for this simple question. I have a Gridview1 with 2 columns. I added
a 3rd column and all I want to do is add the numbers in the 1st and 2nd
column together for the 3rd column. Can someone tell me where I can put the
code in Visual Studio 2005 and how I tell the Gridview to do the simple
math?

Is there a site that will teach me exactly this? I googled but didn't find
exactly this.
Sep 22 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: barnesc | last post by:
Hi! Here's a simple hashcash implementation in Python. 28 lines of actual code. Can be reduced to 17 lines for instructional purposes, if you don't want clustering, and use xrange() instead...
2
by: Senraba | last post by:
I would like to have a 600 X 400 window open with search results from CPanel's Entropy Search form. I have the following in the <HEAD> tag: <script language="javascript"...
2
by: Webdiyer | last post by:
Hi, We all know that the return value of Math.Log(8,2) is 3,but how about (int)Math.Log(8,2)? On my machine,the return value of (int)Math.Log(8,2) is strange enough! it's not 3 but 2 ! I've...
3
by: vezquex | last post by:
What I want is an element with a shifting background image: <html><head> <script type="text/javascript"> var x = 0 var y = 0 inc = 4 function bgWander(el){ x = x +...
2
by: Phillip Vong | last post by:
Sorry about this simple question. I'm running ASP.NET 2.0 using VS2005. I have a simple Gridview. I have a column named "WhoUpdate" with visible = False. <asp:BoundField...
1
by: macklin01 | last post by:
Hi, everybody. I'm trying to do some last cleaning up on the following php page I wrote: http://www.math.uci.edu/~pmacklin/Publications.php This URL parses an XML file of publications: ...
10
by: Ron | last post by:
I want to calculate the surface area of a sphere from an inputed radius with option strict on. I guess I am not converting something correctly. Here is what I am doing: I have a textbox...
5
by: gray_slp | last post by:
I am designing a web survey using surveymonkey.com and discovered I could use javascript to modify their standard question formats much the same as can be done in myspace. I used this feature to...
22
by: giordan | last post by:
Hi all! I've wrote this code: <script type="text/javascript"> var largImg; var altImg; var txtTop = '<b>Ottima scelta!</b> Ora compila il form e premi "Ricevi banner". Il...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.