Datagrid Boundcolumn conditional formating
I have a datagrid:
VB Code:
<asp:datagrid id="dgMaster" runat="server" EnableViewState="False" AutoGenerateColumns="False" >
<AlternatingItemStyle backcolor="Firebrick" ForeColor="White"></AlternatingItemStyle>
<ItemStyle backcolor="Gainsboro"></ItemStyle>
<HeaderStyle font-bold="True" forecolor="White" backcolor="#6699CC"></HeaderStyle>
<Columns>
<asp:BoundColumn DataField="Service Date" HeaderText="Service Date" DataFormatString="{0:d}"></asp:BoundColumn>
<asp:BoundColumn DataField="Description" HeaderText="Description" ></asp:BoundColumn>
<asp:BoundColumn DataField="Charges" HeaderText="Charges" DataFormatString="{0:c}">
<asp:BoundColumn DataField="Payments" HeaderText="Payments" DataFormatString="{0:c}">
</asp:BoundColumn>
</Columns>
</asp:datagrid>
now the payments and the charges column will include 0 as a value, and having DataFormatString="{0:c}", the result is $0.00.
I would like to replace the $0.00 with say something like "-" or even an empty string. will i have to change the columns to templated column to acheive this, or is there another way around this?
Thanks.
Re: Datagrid Boundcolumn conditional formating
I am not aware of a way of doing this using the BoundColumn type you'll need to use a TemplateColumn.
Code:
<asp:TemplateColumn HeaderText="Charges">
<%# displayPrice((string) DataBinder.Eval(Container.DataItem, "Charges", "{0:c}")) %>
</asp:TemplateColumn>
and then in the code behind:
Code:
string displayPrice(charges) {
if (charges == "£0.00") {
return "-";
} else {
return charges;
}
}
HTH
DJ