Solved

Format Column in Gridview

Posted on 2006-07-11
1
424 Views
Last Modified: 2012-06-22
Morning,

im connecting to a access database and it returns the values fine in my gridview, but im having diffilculty formating the fields

the date column is returned as "11/07/2006 00:00:00" and I just want "11/07/2006"

ive tried:
<asp:BoundField DataField="HDate" HeaderText="Date" DataFormatString="{0:MM/dd/yyyy}"/>
<asp:BoundField DataField="HDate" HeaderText="Date" DataFormatString="{0:d}" />

but still get "11/07/2006 00:00:00"

any ideas?

Also the other column returns a number "7.00200000000001" and I just want to round it up or down "7"

not sure about this one but tried
<asp:BoundField DataField="Free" HeaderText="Free" DataFormatString="{0:g}" />

but still get  "7.00200000000001"

thanks
0
Comment
Question by:ziwez0
1 Comment
 
LVL 10

Accepted Solution

by:
SystemExpert earned 500 total points
ID: 17080133
Hi

use this in your databound event

Convert.ToDateTime(drAdded[rowindex]["EFFECTIVEDATEFROM"]).ToString("MM/dd/yyyy")

protected void itemDataBound(object sender, DataGridItemEventArgs e)
  {      
            if  (e.Item.ItemType!=ListItemType.Header && e.Item.ItemType!=ListItemType.Footer)    

             {
                    &nbs p; total += float.Parse(e.Item.Cells[1].Text);
                      e.Item.ForeColor = System.Drawing.Color.Blue;
                 }
                 else if (e.Item.ItemType == ListItemType.Footer)
                {
                     e.Item.Cells[0].Text = "Total";
                     e.Item.Cells[1].Text = total.ToString();
                }
          }

hope you get my point what i try to say

Thanks
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Angular - break the dataset in chunks? 7 51
Exit the loop 4 43
C# bracket error 3 32
Winforms -- Capture CTRL+SHIFT+D at the form not working? 3 22
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

822 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question