I have a unique situation. I am trying to get a field to subtract from a total based on a column in the grid and an overall total.
I am able to get this to work when the grid is first created...
here is my code:
The grid is created from a child class that is a property of the parent class using the OnNeedDataSource method. The Total amount is in the parent class.
So after getting the total I am doing my calculation after the grid is bound using data in a column of the child class.
So basically it shows the funding being deducted from the total amount for every row in the grid until the total amount left is 0.
This works great when the grid first loads, but if I hit the refresh button on the grid or try to export this to pdf, the calculation disappears.
Of course I have Ajax in the page for updating the grid etc. So I turn it off when I export to pdf like I'm supposed to, but the data still doesn't show.
The rest of the bound data does show up on refresh and on export, just this column doesn't get updated. I have stepped through the code and it the data gets created on refresh or export, but still doesn't show up when the page is rendered or exported.
Any ideas or help would be appreciated. Let me know if you need any more info.
Thanks,
Dustin
I am able to get this to work when the grid is first created...
here is my code:
The grid is created from a child class that is a property of the parent class using the OnNeedDataSource method. The Total amount is in the parent class.
public
void
grdSiteFunding_NeedDataSource(
object
sender, GridNeedDataSourceEventArgs e)
{
SiteFundingCalculation sfc =
new
SiteFundingCalculation(2010);
if
(TotAmnt <= 0)
{
TotAmnt = sfc.CalculateNetFunds();
TotLeft = TotAmnt;
}
if
(TotLeft <= 0)
{
TotLeft = TotAmnt;
}
//Bind the grid to the child class.
grdSiteFunding.DataSource = sfc.FundingDetails.ToList();
}
So after getting the total I am doing my calculation after the grid is bound using data in a column of the child class.
protected decimal TotAmnt = 0;
protected decimal TotLeft = 0;
public
void
grdSiteFunding_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridDataItem)
{
GridDataItem dItem = (GridDataItem)e.Item;
decimal
oFunds = 0;
decimal
cFunds = 0;
oFunds =
decimal
.Parse(dItem[
"OverriddenFunding"
].Text.Replace(
"$"
,
""
).Trim());
cFunds =
decimal
.Parse(dItem[
"CalculatedFunding"
].Text.Replace(
"$"
,
""
).Trim());
decimal
retVal = 0;
if
(oFunds > 0)
{
if
(oFunds <= TotLeft)
{
retVal = TotLeft - oFunds;
TotLeft -= oFunds;
}
else
{
retVal = TotLeft;
if
(TotLeft != 0)
TotLeft -= TotLeft;
}
}
else
if
(TotLeft >= cFunds)
{
if
(cFunds <= TotLeft)
{
retVal = TotLeft - cFunds;
TotLeft -= cFunds;
}
else
{
retVal = TotLeft;
if
(TotLeft != 0)
TotLeft -= TotLeft;
}
}
else
{
retVal = TotLeft;
if
(TotLeft != 0)
TotLeft -= TotLeft;
}
dItem[
"RemainingFunds"
].Text = retVal.ToString(
"C"
);
}
}
So basically it shows the funding being deducted from the total amount for every row in the grid until the total amount left is 0.
This works great when the grid first loads, but if I hit the refresh button on the grid or try to export this to pdf, the calculation disappears.
Of course I have Ajax in the page for updating the grid etc. So I turn it off when I export to pdf like I'm supposed to, but the data still doesn't show.
The rest of the bound data does show up on refresh and on export, just this column doesn't get updated. I have stepped through the code and it the data gets created on refresh or export, but still doesn't show up when the page is rendered or exported.
Any ideas or help would be appreciated. Let me know if you need any more info.
Thanks,
Dustin