Loading a dtatgrid with values from another datagrid...

  • Thread starter Thread starter Coleen
  • Start date Start date
C

Coleen

Hi all :-)

We are using a DB2 database connection through a class module to get the
data into a datagrid in an aspx web page using VB.Net. I can get the data
into the first datagrid with no problem, however, since I need to do a bunch
of calculations with these values AND pull values for two session variable
within the web application, I need to create another datagrid to display the
calculations. Here is what I'm doing:

dtg_stat_report_1.DataSource =
lo_AZRM010A.get_dt_stat_report_1
dtg_stat_report_1.DataBind()
For i = 0 To dtg_stat_report_1.Items.Count - 1
dgi = dtg_stat_report_1.Items(i)
ls_bus_name = dgi.Cells(0).Text
ls_gas_gal = dgi.Cells(1).Text.Trim.Replace(",",
"").Replace(" ", "").Replace(" ", "")
ls_gasohol_gal = dgi.Cells(2).Text.Trim.Replace(",",
"").Replace(" ", "").Replace(" ", "")
If ls_gas_gal = "" Then ls_gas_gal = "0"
If ls_gasohol_gal = "" Then ls_gasohol_gal = "0"
li_gas_gal = CInt(ls_gas_gal)
li_gasohol_gal = CInt(ls_gasohol_gal)

li_st_1265_tax = (li_gas_gal + li_gasohol_gal) *
0.12397
li_st_5_tax = (li_gas_gal + li_gasohol_gal) * 0.049
li_cty_535_tax = (li_gas_gal + li_gasohol_gal) *
0.05243
li_cty_opt_tax = Session("tot_cty_opt_tax")
li_cty_1_tax = (li_gas_gal + li_gasohol_gal) *
0.0098
li_CPI_tax = Session("wa_tot_gal")

dtg_display.DataSource = of_ref_table()
dtg_display.DataBind()
'Fill the variables in dtg_display with the values
from above
For j = 0 To dtg_display.Items.Count - 1
dtg_display.Items(1).Cells(0).Text = ls_bus_name
dtg_display.Items(1).Cells(1).Text = ls_gas_gal
dtg_display.Items(1).Cells(2).Text =
ls_gasohol_gal
dtg_display.Items(1).Cells(3).Text =
li_st_1265_tax
dtg_display.Items(1).Cells(4).Text = li_st_5_tax
dtg_display.Items(1).Cells(5).Text =
li_cty_535_tax
dtg_display.Items(1).Cells(6).Text =
li_cty_opt_tax
dtg_display.Items(1).Cells(7).Text =
li_cty_1_tax
dtg_display.Items(1).Cells(8).Text = li_CPI_tax

Next

The of_ref_table() creates the columns for the new datagrid, but I cannot
get the values to populate. I know I need to do something like
dtg_display.row(i).add, but this is not available to me. Any suggestions?
TIA,

Coleen
 
Hi Coleen,

A couple things...first, the best way to fill a data grid is directly from a data source. Try filling your second data grid from a data table or data view instead of from the first data grid.

Also, you've probably already caught this, but your second For...Next loop never makes reference to your index counter (j), so it is just overwriting the first row multiple times.

Take care,

Eric
 
Hi Eric - Thanks - I had not caught that yet, I've been side tracked on
something else...the problem we have with getting our data directly from a
data source is the way we connect to the DB2 database using class modules.
I have to populate the page in the code behind from the values in the first
datagrid because we can't pull session variables in the class module, thus I
have to do all my calculations and get my session variables in the code
behind. If I can create a dataview instead of a datagrid that would be
great, since I don't want to display the first datagrid any ways. I will
try that...Thanks again :-)

Hi Coleen,

A couple things...first, the best way to fill a data grid is directly from a
data source. Try filling your second data grid from a data table or data
view instead of from the first data grid.

Also, you've probably already caught this, but your second For...Next loop
never makes reference to your index counter (j), so it is just overwriting
the first row multiple times.

Take care,

Eric
 
Sounds good. Also, a "heads up" on your calculations...

You might want to reference the underlying data table instead of your data view when number crunching. This cuts out the "middle man", so you can streamlined your performance a bit (pardon the cliché). The data view will need to reference the data table anyway, so that is at least one less registry (at least) per calculation to use during processing.

Another common problem with data views is maintaing synchronization between that and the underlying table. When you add/delete the rows using a data view, it can easily throw off the indexing when the binding context position changes (until the data source is update). Hitting the table directly can mostly take care of this.

Take care,

Eric
 
Thanks very much for the heads up and the advice, I appreciate it :-)
Sounds good. Also, a "heads up" on your calculations...

You might want to reference the underlying data table instead of your data view when number crunching. This cuts out the "middle man", so you can streamlined your performance a bit (pardon the cliché). The data view will need to reference the data table anyway, so that is at least one less registry (at least) per calculation to use during processing.

Another common problem with data views is maintaing synchronization between that and the underlying table. When you add/delete the rows using a data view, it can easily throw off the indexing when the binding context position changes (until the data source is update). Hitting the table directly can mostly take care of this.

Take care,

Eric
 
Back
Top