Bind to ASP Table instead of Datagrid

C

coleenholley

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
 
M

Michael Ramey

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

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 :)
Community Website: http://www.dotnetjunkies.com/newsgroups/
 
C

coleenholley

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...
 
M

Michael Ramey

Could you do the calculations in your datasource?

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

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...Community Website: http://www.dotnetjunkies.com/newsgroups/
 
C

coleenholley

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
 
A

Alvin Bruney [MVP]

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
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 helpCommunity Website: http://www.dotnetjunkies.com/newsgroups/
 
C

coleenholley

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,072
Latest member
trafficcone

Latest Threads

Top