473,788 Members | 2,893 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calculated cell in GridView

gchq
96 New Member
Using both static data and data from some GridView cells I am attempting to calculate a result in a Template Cell - but to no avail!

The value for TextBox1 is brought in on the page_load event and I'm attempting the balance of the calculation uisng the ItemDataBound event :-

Expand|Select|Wrap|Line Numbers
  1.  
  2. Protected Sub GridView1_ItemDataBound(ByVal sender As Object, ByVal e As DataGridItemEventArgs)
  3.         If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
  4.             Dim vInterest As Single = TextBox1.Text / 100.0#
  5.             Dim vRate As Single = 1.0#
  6.             Dim vRemLife As Single = e.Item.Cells(3).Text
  7.             Dim vCostAv As Single = e.Item.Cells(4).Text
  8.             Dim vNum As Integer
  9.             For vNum = 1 To vRemLife
  10.                 vRate = vRate * (1 + vInterest)
  11.             Next vNum
  12.             Dim vInsert As Single = Format(vCostAv * vRate, "###.##.0.00")
  13.             e.Item.Cells(5).Text = vInsert
  14.         End If
  15.  
  16.  
But the calculated cells are always empty at run time! Any ideas what where I'm going wrong?
Feb 2 '07 #1
3 1745
Killer42
8,435 Recognized Expert Expert
Have you stepped through the code to make sure it's doing what you expect, and when you expect it?
Feb 2 '07 #2
gchq
96 New Member
Have you stepped through the code to make sure it's doing what you expect, and when you expect it?
I re-jigged it - and now it works :-)

Expand|Select|Wrap|Line Numbers
  1.  
  2. Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
  3.         If e.Row.RowType = DataControlRowType.DataRow Then
  4.             Dim vInterest As Single = TextBox1.Text / 100.0#
  5.             Dim vRate As Single = 1.0#
  6.             Dim vRemLife As Single = Convert.ToSingle(DataBinder.Eval(e.Row.DataItem, "Rem_Life"))
  7.             Dim vCostAv As Single = Convert.ToSingle(DataBinder.Eval(e.Row.DataItem, "Cost_Av"))
  8.             Dim vNum As Integer
  9.             For vNum = 1 To vRemLife
  10.                 vRate = vRate * (1 + vInterest)
  11.             Next vNum
  12.             Dim vInsert As Single = vCostAv * vRate
  13.             Dim vInsert2 As String = Format(vInsert, "###,##0.00")
  14.             e.Row.Cells(6).Text = vInsert2
  15.         End If
  16.     End Sub
  17.  
  18.  
Feb 3 '07 #3
Killer42
8,435 Recognized Expert Expert
Ok. Glad to see you've resolved it.
Feb 4 '07 #4

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

Similar topics

1
5391
by: Miguelito Bain | last post by:
hi everybody. i'm trying to find out what you can and can't do with/in calculated fields. any help, pointers, and/or advice would be greatly appreciated. i'm a newbie, but i want to learn, and i've tried a lot before posting. here's my situation. i have a simple form with dates on it. i have an indate and outdate
1
9389
by: Jon S via DotNetMonster.com | last post by:
HI all, I'm returning a dataset to a gridview control. When the gridview asp.net control is populated from the returning dataset some of the cells remain empty. This is expected as some data in the dataset is empty. The cells that are empty, in the gridview control, I would like to have the value of 0 (zero) inserted. Is there a default cell value property or something similar for the asp.net gridview control. So if no data is...
2
8003
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 field called AVG, I want to be able to sort based on AVG when they click on AVG. I can't seem to find a way to do this out there. Thanks!
1
27504
by: K B | last post by:
I would like to create a gridview as below: Project Name 1-1 1-2 1-3 1-4 1-5 1-6 Project 1 BLUE BLUE BLUE BLUE GREEN GREEN more projects I would like to fill the cell with a solid color based on the value of the cell (e.g., documents that are complete (blue) or not complete (green). In effect have a solid bar indicator going across each row. I know how to color the cell based on the value, but not the click...
2
5491
by: =?Utf-8?B?TWlrZQ==?= | last post by:
Hi, I can return the rowindex using SelectedRow or SelectedIndex But, how do I get my code to return the cell or column index of a selected row in my gridview? thanx -- Regards,
3
3311
by: Bill Gower | last post by:
I have an cell which contains a field member which is filled with String.Empty. When I retrieve the value in the cell with Cells.Text.ToString() and try to compare it to String.Empty, I can't because it contains "&nbsp". I really don't want to compare the value to that so how can I retrieve an empty cell so that it is String.Empty. Bill
2
1455
by: =?Utf-8?B?TWlrZQ==?= | last post by:
Hi, I've bind a grdiview to a database and it's working fine. but what I want to do is if the data in certain cell exceed the cell width the that cell will only show the words with some dots implying to the user that is more data that should be seen. meaning that if the data to be shown in a cell is e.g: "This is my data an it's very long that why I'm showing it all" I would like cell just showing the first words followed by dots like...
14
91372
by: Mike | last post by:
I have a gridview that has a button in the last cell of each row. I want to get the text from cell 1 for that row the button was clicked on. So if my gridview looks like this: N-12 BMW N-35 Mercedes if my user clicks row 2, I want to see Mercedes, How can I do that? I have a buttonClick event for my select button, I'm trying to pull the values using the DataKeyName, but I keep getting 'object reference...
4
5864
by: foolmelon | last post by:
Before AJAX, we were able to focus a cell in a gridview during a fullpage postback. After putting the gridview inside an UpdatePanel, we cannot focus a cell in this gridview anymore. Does anybody know if it is possible to make such focus? Thanks! Bill
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10366
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10173
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9967
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5399
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4070
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.