Results 1 to 2 of 2

Thread: Datagrid Boundcolumn conditional formating

  1. #1

    Thread Starter
    Hyperactive Member johnweidauer's Avatar
    Join Date
    Sep 2002
    Location
    SLC, UT
    Posts
    314

    Datagrid Boundcolumn conditional formating

    I have a datagrid:

    VB Code:
    1. <asp:datagrid id="dgMaster" runat="server"  EnableViewState="False" AutoGenerateColumns="False" >
    2.  
    3. <AlternatingItemStyle backcolor="Firebrick" ForeColor="White"></AlternatingItemStyle>
    4. <ItemStyle backcolor="Gainsboro"></ItemStyle>
    5. <HeaderStyle font-bold="True" forecolor="White" backcolor="#6699CC"></HeaderStyle>
    6. <Columns>
    7.  
    8. <asp:BoundColumn DataField="Service Date" HeaderText="Service Date" DataFormatString="{0:d}"></asp:BoundColumn>
    9.  
    10. <asp:BoundColumn DataField="Description" HeaderText="Description" ></asp:BoundColumn>
    11.  
    12. <asp:BoundColumn DataField="Charges" HeaderText="Charges" DataFormatString="{0:c}">
    13.  
    14. <asp:BoundColumn DataField="Payments" HeaderText="Payments" DataFormatString="{0:c}">
    15. </asp:BoundColumn>
    16. </Columns>
    17. </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.
    To the world you may just be one person, but to this one person, you just might be the world.

  2. #2
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131

    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

    If I have been helpful please rate my post. If I haven't tell me!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width