My client wants to have an option to hide as he see fits. I worked around the problem to treat $0 as the special case, in which I would display a custom message instead of the price.
First, I declare a constant in the Search.cs
protected const string CALL_MESSAGE = "CALL";
Then I add the two functions within the class:
protected string PriceToString(object price) {
return PriceToString(Convert.ToInt32(price));
}
protected string PriceToString(int price) {
return (price > 0) ? string.Format("{0:C2}", price) : CALL_MESSAGE;
}
In the showad.cs, I modify the AdDetails_ItemDataBound function to display the custom message:
protected
void AdDetails_ItemDataBound(object sender, RepeaterItemEventArgs e) {
...
if (ad != null) {
...
AdPriceLabel.Text = (ad.Price > 0) ? String.Format("{0:c}", ad.Price) : CALL_MESSAGE;
...
}
...
}
In search.aspx, I Changed the itemtemplate in the datagrid to
...
<asp:TemplateField HeaderText="Price" SortExpression="Price">
<ItemTemplate><%# PriceToString(Eval("Price")) %></ItemTemplate>
...
Finally, you may also want to change the label in the PostAd.aspx from price to something like "Price: (0 for CALL)", etc.
My solution is pretty much a hack. You may be able to find better solutions with similar idea. Please let me know if it works out for you.