473,395 Members | 1,774 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,395 software developers and data experts.

calculated column in gridview

parshupooja
159 100+
Hi All,

I have gridview with following columns
date--morningin--morningout--afetrnoonin--afetrnoonout

I want to create another 6th coulmn which shd display total hours(morningout-morningin)+(afternoonout-afetrnoonin)

Can anyone help me with this?
I am fed up of trying.

thanks
Sep 17 '07 #1
7 4793
Plater
7,872 Expert 4TB
This is a webapplication?
Are you going to do it in the SQL statement or afterwards in just the gridview?
Sep 17 '07 #2
parshupooja
159 100+
Yes it is a webapplication and gridview date is coming from store procedure of SQL Server . Also this is built in asp.net C#
thanks
Sep 17 '07 #3
Plater
7,872 Expert 4TB
I ment were you planning on changing your SQL statement to have the computed column included in the query, or were you going to do it in code?

If those columns represent valid dates, create DateTime objects from them and then do the math that way. They will produce TimeSpan objects that you can use to determine total number of hours.
Sep 17 '07 #4
parshupooja
159 100+
Sorry abt that. I want to calculate in code of asp.net not in SQL .

I ment were you planning on changing your SQL statement to have the computed column included in the query, or were you going to do it in code?

If those columns represent valid dates, create DateTime objects from them and then do the math that way. They will produce TimeSpan objects that you can use to determine total number of hours.
Sep 17 '07 #5
Plater
7,872 Expert 4TB
Sorry abt that. I want to calculate in code of asp.net not in SQL .
ok, so do the DateTime thing, should be pretty easy
Sep 17 '07 #6
parshupooja
159 100+
How shd i do math? can u show a little snippet

date morning in morningout afternoon in afternoonout

09/17/2007 9 am 11pm 1pm 5pm

ok, so do the DateTime thing, should be pretty easy
Sep 18 '07 #7
Plater
7,872 Expert 4TB
Well you can either do math on just the numbers.
(I assume that should be 11am and not 11pm?)
9am=9
11am=11
1pm=13
5pm=17

11-9=2
17-13=4
4+2=6


OR you can try and create a DateTime object for each one
Like for example:
Expand|Select|Wrap|Line Numbers
  1. //this might not work, you might have to get crafty-er with your creation
  2. DateTime mi=DateTime.Parse(data.ToString()+" "+morningin.ToString());
  3. DateTime mo=DateTime.Parse(data.ToString()+" "+morningout.ToString());
  4. TimeSpan tm= mo-mi;
  5. //now "tm" contains the amount of time between the two times.
  6.  

Creating DateTime objects successfully would allow you to do partial hour amounts much easier then just creating integers numbers out of them.
Sep 18 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Hans Merkl | last post by:
Hi, Is there a way to show the column headers of a GridView control even if there is no data? The only thing I see is the EmptyDataTemplate but I would also like to display the column headers. ...
1
by: Manish | last post by:
Hello Everyone I am having weird problem in my datagrid bounded to datatable. My datatable is populated from SQLServer database. DataGrid has Calculated column Week% and Calculated record, SPLH....
1
by: James Rosewell | last post by:
I'm getting an error in the following scenario. - A GridView control is bound to an SQLDataSource. - The user selects a column for sorting. - Some time later in code the column used for sorting...
1
by: sck10 | last post by:
Hello, I am using the following DataSource with a GridView. My question is how do I show the calculated field in a GridView for the following: RevenueQtr01 + RevenueQtr02 + RevenueQtr03 +...
2
by: markm75c | last post by:
Does anyone know of a way to sort a column which isnt databound or an actual field in the database, but is derived from a method? IE. I have a grid showing stats for softball, with a calculated...
1
by: Eric | last post by:
I have a GridView control that I want to sort on multiple columns when I click a particular column. For example, I display Last name + ", " + First name in the first column and display id in the...
4
by: bryan | last post by:
Hi all, I am working on a .net 2.0 web app. On page load I display a gridview with a drop down list (Employees), when the user selects from the drop down list, the grid view is filled with...
3
by: =?Utf-8?B?Um9iZXJ0IFNtaXRo?= | last post by:
Hi, I have a GridView with a checkbox column in it called FromInsight, however this is not bound to the dataset, its value is based on another column from the dataset called sourceid For each...
2
by: SammyBar | last post by:
Hi, I'm trying to display a DataSet data by using a GridView control on Visual Studio 2005 professional. I'm displaying the DataSet directly, without using the DataSource object. I can display...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.