Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Formatting percentage with Bind method in Gridview

Posted on 2008-10-03
2
Medium Priority
?
2,085 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

664 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