Solved

Formatting percentage with Bind method in Gridview

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

821 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