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