Solved

Formatting percentage with Bind method in Gridview

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

820 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