Solved

Format Column in Gridview

Posted on 2006-07-11
1
404 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now