Format GridView Colums to 1 decimal place



HI I have the following gridview how can I format the data to 1decimal place??

Is there a property as I can't seem to see anything??

Thanks,





 <asp:GridView ID="gvSurveyResults" runat="server" AutoGenerateColumns="False" DataSourceID="ObjectDataSource11"
                CellPadding="4" ForeColor="#333333" GridLines="None" OnLoad="gvSurveyResults_Load" Font-Names="Arial, Small Caps"  Font-Size="Larger">
                <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" Font-Names="Arial, Small Caps"
                />
                <RowStyle BackColor="#EFF3FB" />
                <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                <EditRowStyle BackColor="#2461BF" />
                <AlternatingRowStyle BackColor="White" />
                <Columns>
                    <asp:BoundField DataField="Text" HeaderText="Question" SortExpression="Text" />
                    <asp:BoundField DataField="AvgResponseValue" HeaderText="Avg Question Value For All Responses" ReadOnly="True"
                        SortExpression="AvgResponseValue" />
                </Columns>
            </asp:GridView>
            <asp:ObjectDataSource ID="ObjectDataSource11" runat="server" OldValuesParameterFormatString="original_{0}"
                SelectMethod="GetData" TypeName="SurveyDataSetTableAdapters.GetAvgResponseValueTableAdapter">
                <SelectParameters>
                    <asp:SessionParameter Name="surveyId" SessionField="SurveyId" Type="Int32" />
                </SelectParameters>
            </asp:ObjectDataSource>
            <asp:ObjectDataSource ID="ObjectDataSource1" runat="server"></asp:ObjectDataSource>
bailey1200Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

asp_net2Commented:
Add the Format String for your BoundField to use {0:P1} for one decimal place or you can also handle this in your SQL code.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
asp_net2Commented:
I also had to do the same thing myself and I had to set the field in my database to use the decimal type and I changed the precision to 6 and scale to 1. Then I used the following SQL statement below.

select field1, field2, field3/100 as decimalfield
from tablename
0
bailey1200Author Commented:
Hi
In here: <asp:BoundField FormatString="" >

I dont seem to have a bound format string  property avaliable to me...
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

bailey1200Author Commented:
Hi I have found
DataFormatString="{0:P1} " but this doesn't do anything! Any ideas?
0
asp_net2Commented:
>> DataFormatString="{0:P1} " but this doesn't do anything! Any ideas?

This is correct, you can also try 0:P2.

Can you post example data that is stored in your decimal field?? That would help out along with posting your code.
0
bailey1200Author Commented:
Hi thanks i have that working now but it is changing the figures to pecentages and I need it to be 2decimal places!
0
Alfred A.Commented:
You can try something like this,

<asp:boundfield headertext = "Price"
   datafield = "Price"
   dataformatstring = "{0:F1}"
   itemstyle-horizontalalign = "right" />
0
Alfred A.Commented:
For two decimal places,

dataformatstring = "{0:F2}"
0
Alfred A.Commented:
Actually, this should be find for two decimal places.

dataformatstring = "{0:F}"
0
asp_net2Commented:
Try the following below and let me know how it works.

{0:F2}
or
{0:D} or {0:D2}
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.