Solved

Formatting percentage with Bind method in Gridview

Posted on 2008-10-03
2
2,066 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Suggested Solutions

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

752 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