By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,225 Members | 2,170 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,225 IT Pros & Developers. It's quick & easy.

Bind to ASP Table instead of Datagrid

P: n/a
I have a Class Module written in VB that calls an RPC (written in COBOL) we have written code to read the data from the RPC, and we create a temporary datatable to store the data from the RPC. This works fine when we call the datatable and bind it to a data grid using datagridname.DataBind(), but I have an ASP table, with calculations using tbl_name.row(1).cells(1) and the result of the calculation is put in a specific row and cell.

I have calculations throughout the table based on tbl_name.Rows(1).cells(1). I can't see how to do these types of calculations in a datagrid, and am not sure how to bind the datatabe to the ASP table. Can anyone help with either the bind to the datatable, or the way to calculate on a specific row and cell in a datagrid? Thanks for any help :-)

Coleen

---
Posted using Wimdows.net NntpNews Component - Posted from .NET's Largest Community Website: http://www.dotnetjunkies.com/newsgroups/
Nov 18 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
You won't be able to bind a datasource to an asp:table, it just doesn't have
a functionality, the web controls DataGrid/DataList were meant for that.
Here's what you can do though,

asp:table - you can create your own table from the datasource, and keep
track of values you need to calculate (I would suggest doing this if you are
doing some funky calculations within the table)

For the DataGrid, check into the OnItemDataBound property / ItemDataBound
event, you can look at any/all the data you want before it's actually bound
to the Datagrid, that way you can keep track of certain fields, and do
calculations, etc.

HTH,
--Michael

<coleenholley> wrote in message
news:eS**************@TK2MSFTNGP10.phx.gbl...
I have a Class Module written in VB that calls an RPC (written in COBOL) we have written code to read the data from the RPC, and we create a
temporary datatable to store the data from the RPC. This works fine when we
call the datatable and bind it to a data grid using datagridname.DataBind(),
but I have an ASP table, with calculations using tbl_name.row(1).cells(1)
and the result of the calculation is put in a specific row and cell.
I have calculations throughout the table based on tbl_name.Rows(1).cells(1). I can't see how to do these types of
calculations in a datagrid, and am not sure how to bind the datatabe to the
ASP table. Can anyone help with either the bind to the datatable, or the
way to calculate on a specific row and cell in a datagrid? Thanks for any
help :-)
Coleen

---
Posted using Wimdows.net NntpNews Component - Posted from .NET's Largest

Community Website: http://www.dotnetjunkies.com/newsgroups/
Nov 18 '05 #2

P: n/a
I could use the datagrid if I knew how to do the calculations for rows and columns...in other words, I need to multiply across and down:

row1.cell1 X row1.cell2 = row1.cell3

then I need the sum everytihing in column1 (which is cell1) as a grand total, sumofcolumn2(cell2) as a grand total and sumof column3(cell3) as a grand total.

I found an article on how to do the calculations as grand totals in a footer, but I can't find anything in VB on how to do the calculations across for row1.cell1 X row1.cell2 = row1.cell3

If you can provide me with a sample in VB of how to do the calculations across, I would be in your debt...

---
Posted using Wimdows.net NntpNews Component - Posted from .NET's Largest Community Website: http://www.dotnetjunkies.com/newsgroups/
Nov 18 '05 #3

P: n/a
Could you do the calculations in your datasource?

sql for example
"Select column1, column2, column1*column2 as column3 from mytable"

<coleenholley> wrote in message
news:Od**************@TK2MSFTNGP11.phx.gbl...
I could use the datagrid if I knew how to do the calculations for rows and columns...in other words, I need to multiply across and down:
row1.cell1 X row1.cell2 = row1.cell3

then I need the sum everytihing in column1 (which is cell1) as a grand total, sumofcolumn2(cell2) as a grand total and sumof column3(cell3) as a
grand total.
I found an article on how to do the calculations as grand totals in a footer, but I can't find anything in VB on how to do the calculations across
for row1.cell1 X row1.cell2 = row1.cell3
If you can provide me with a sample in VB of how to do the calculations across, I would be in your debt...
---
Posted using Wimdows.net NntpNews Component - Posted from .NET's Largest

Community Website: http://www.dotnetjunkies.com/newsgroups/
Nov 18 '05 #4

P: n/a
No, we are NOT using an SQL Database connection...the way we connect is part of the problem. To make a long story short, I can NOT do the calculation in an SQL statement, because I can't write an SQL statement to use in my connection. We use DB2 through a convoluded COBOL process. All my calculations have to be done on the Front end - in the web page. So I realy need a way to do calculations in the datagrid...thanks for any help

---
Posted using Wimdows.net NntpNews Component - Posted from .NET's Largest Community Website: http://www.dotnetjunkies.com/newsgroups/
Nov 18 '05 #5

P: n/a
This is typically a straightforward process. In your itemdatabound event
handler you would do this
if(e.item.itemtype == listitem.item || e.item.itemtype ==
listitem.alternateitem)
e.item.cells[3].text = (Double.Parse(e.item.cells[1].text) *
Double.Parse(e.item.cells[2].text)).ToString()

There are a couple of issues here you need to be aware of. Parse will
explode on a null or empty value. Either check for null or empty, or wrap it
in a try catch block. Infact, the best way forward would be to use the
doubles tryparse functionality which avoids the penalty of an exception
The syntax is Double.TryParse. Here is an example:
double cell1=0, cell2=0;

if(Double.TryParse(e.Item.Cells[2].Text, NumberStyles.Number,
NumberFormatInfo.InvariantInfo, out cell1))

{

if(Double.TryParse(e.Item.Cells[2].Text, NumberStyles.Number,
NumberFormatInfo.InvariantInfo, out cell2))

{

e.item.cells[3].text = (cell1 * cell2).ToString();

}

}

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
<coleenholley> wrote in message
news:u5**************@TK2MSFTNGP12.phx.gbl...
No, we are NOT using an SQL Database connection...the way we connect is part of the problem. To make a long story short, I can NOT do the
calculation in an SQL statement, because I can't write an SQL statement to
use in my connection. We use DB2 through a convoluded COBOL process. All
my calculations have to be done on the Front end - in the web page. So I
realy need a way to do calculations in the datagrid...thanks for any help
---
Posted using Wimdows.net NntpNews Component - Posted from .NET's Largest

Community Website: http://www.dotnetjunkies.com/newsgroups/
Nov 18 '05 #6

P: n/a
I really appreciate your help; however, I am programming VB.net, not C#. I'm sorry, but the example you sent me only confuses me...I know nothing about C#. Maybe you could send an example in VB? Thanks for your help :-

Coleen

---
Posted using Wimdows.net NntpNews Component - Posted from .NET's Largest Community Website: http://www.dotnetjunkies.com/newsgroups/
Nov 18 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.