Update the FooterText of DataGrid programatically

G

Gheorghe Popescu

Hello,

I created a DataGrid control with two columns:
- a template column that contains a checkbox with AutoPostBack set to
true:
<asp:TemplateColumn>
<ItemTemplate>
<asp:CheckBox Runat="server" ID="chkPay" AutoPostBack="True" />
</ItemTemplate>
</asp:TemplateColumn>
- a databound column that contains an monetary field. This column also
has a footer where I want to show the total of all checked columns.

I am doing the following:
private void Page_Load(...)
{
if (!IsPostBack)
{
grid.DataSource = ...;
grid.DataMember = ...;
grid.DataBind();
}
}

private void Page_PreRender()
{
double _total = 0;
// Recalculate the total
foreach (DataGridItem dgi in grid.Items)
{
CheckBox cb = (CheckBox) dgi.Cells[0].Controls[1];
if (cb.Checked)
{
string amount = ((Label) dgi.Cells[2].Controls[1]).Text;
_total += double.Parse(amount, NumberStyles.AllowCurrencySymbol
| NumberStyles.AllowDecimalPoint);
}
}

grid.Columns[1].FooterText = string.Format("{0:c}", _total);
}

This code doesn't set the footer text in the grid (it shows up as
blank). Do you know what I am doing wrong?

Thank you,
Gheorghe Popescu
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top