(Using C# 2.0)
Hi
I was trying to get a field formatted as currency, but could not do
this in my DataGrid unless I did the field as a template field.
However, when I try to create a total row when the row is databound, I
am just getting back that the value is a zerol length string -
presumably because my value is in a label.
How do I get around this? Given that unles the value is in the
template field, for some reason it won't write the £ sign out.
Many thanks
Darren
Source code:
<asp:TemplateField HeaderText="£ Per Night">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%#
Bind("PricePerNight") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#
Bind("PricePerNight", "{0:c}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
Code Behind:
protected void dgRoomBreakdown_ItemDatabound(object sender,
GridViewRowEventArgs e)
{
switch (e.Row.RowType)
{
case DataControlRowType.DataRow:
if (e.Row.Cells[4].Text.Length > 0)
{
dPricePerNight +=
Double.Parse(e.Row.Cells[4].Text);
}
break;
case DataControlRowType.Footer:
e.Row.Cells[4].Text = dPricePerNight.ToString();
break;
}
}