Solved

Formatting percentage with Bind method in Gridview

Posted on 2008-10-03
2
2,028 Views
Last Modified: 2013-12-17
I'm trying to display a column in a gridview using the Bind() function. The column needs to be displayed in percentage format  eg 78%. The gridview code snippet is below. It does not work.

I've tried the following formats
Bind("Lab", "{0:Pn}")
Bind("Lab", "{0:#%}")
Bind("Lab", "{0:P}")


<asp:TemplateField HeaderText="Lab">

                        <itemstyle horizontalalign="Center" />

                        <itemtemplate>

                            <asp:Label id="glblLab" runat="server" Text='<%# Bind("Lab", "{0:Pn}") %>'></asp:Label> 

                        </itemTemplate>

                    </asp:TemplateField>

Open in new window

0
Comment
Question by:Jeffreymarcum
2 Comments
 
LVL 18

Expert Comment

by:David Robitaille
ID: 22634781
try this
Text='<%# Bind("Lab").tostring("P") %>'
0
 

Accepted Solution

by:
Jeffreymarcum earned 0 total points
ID: 22635286
davrob60:

Didn't work. I found the solution myself. I wrote a function that formats the return in percentage
Gridview:
FormatPercentage(Convert.ToString(Eval("Lab")))

Codebehind:
    public string FormatPercentage(string Value)
    {
        return Value + "%";
    }
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

758 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

23 Experts available now in Live!

Get 1:1 Help Now