473,320 Members | 2,177 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,320 software developers and data experts.

Calculated cell in GridView

gchq
96
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 1730
Killer42
8,435 Expert 8TB
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
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 Expert 8TB
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
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...
1
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...
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: 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...
2
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
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...
2
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...
14
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 ...
4
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...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.