惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

爱范儿
爱范儿
宝玉的分享
宝玉的分享
博客园 - 司徒正美
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - 三生石上(FineUI控件)
IT之家
IT之家
博客园 - Franky
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
酷 壳 – CoolShell
酷 壳 – CoolShell
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Blog — PlanetScale
Blog — PlanetScale
Recent Announcements
Recent Announcements
Stack Overflow Blog
Stack Overflow Blog
T
Threatpost
aimingoo的专栏
aimingoo的专栏
博客园_首页
Know Your Adversary
Know Your Adversary
T
Threat Research - Cisco Blogs
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Proofpoint News Feed
Security Latest
Security Latest
T
Tailwind CSS Blog
The Hacker News
The Hacker News
P
Palo Alto Networks Blog
Latest news
Latest news
G
GRAHAM CLULEY
C
CERT Recently Published Vulnerability Notes
Engineering at Meta
Engineering at Meta
A
Arctic Wolf
D
Darknet – Hacking Tools, Hacker News & Cyber Security
I
InfoQ
Y
Y Combinator Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园 - 叶小钗
雷峰网
雷峰网
MongoDB | Blog
MongoDB | Blog
P
Proofpoint News Feed
S
SegmentFault 最新的问题
C
Cybersecurity and Infrastructure Security Agency CISA
Last Week in AI
Last Week in AI
罗磊的独立博客
博客园 - 聂微东
Simon Willison's Weblog
Simon Willison's Weblog
Scott Helme
Scott Helme
T
Tenable Blog
O
OpenAI News
The Cloudflare Blog
大猫的无限游戏
大猫的无限游戏
L
LINUX DO - 热门话题
美团技术团队

博客园 - 赣江源

StreamInsight参考示例 Microsoft StreamInsight简介 GridView中的DataFormatString失效解决办法 - 赣江源 - 博客园 按照时间点还原数据库(SQL Server) 如何显示在线用户? ASP.NET中每个页面在Load之前调用公用函数 网站单点登录的实现思路 在服务器端提取ASP.NET控件输出的HTML 如何处理在IE7关闭时不出现选项卡提示 使用JavaScript控制UpdatePanel的更新 获取GridView单元格值的通用函数 ASP.NET 2.0中使用XSLT的变化 在GridView表头显示排序方向 利用AJAX实现DropDownList与GridView做实时更新 输出时清除GridView的Style ASP.NET实现打印的方法小结 提高ASP.NET性能的一点方法 asp.net的一些小技巧 route命令详解
如何在GridView将数字显示成金额格式或自定义格式?
赣江源 · 2007-11-14 · via 博客园 - 赣江源

Posted on 2007-11-14 16:39  赣江源  阅读(1202)  评论()    收藏  举报

如何在GridView将数字显示成金额格式或自定义格式呢?例如数字是123456.78,GRIDVIEW能否显示成123,456.78格式?
要自定义输出的内容,就只能使用自定义的模板.可以调用ToString()方法输出自定义格式的数据。然后使用ItemTemplate绑定到对应的列。最后通过<%#%>调用对应的函数来格式化显示的数据。
*.aspx代码如下:

<asp:GridView ID="GridView1" runat="server" OnPreRender="GridView1_PreRender" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" AutoGenerateColumns="False">
            
<Columns>
                
<asp:TemplateField>
                
<ItemTemplate>
                
<%# toNumberGroup((int)Eval("c1")) %>
                
</ItemTemplate>
                
</asp:TemplateField>
            
</Columns>
        
        
</asp:GridView>


*.aspx.cs代码如下:

public string toNumberGroup(int i)
    {
        
return i.ToString("n", System.Globalization.CultureInfo.CurrentUICulture.NumberFormat);
    }
protected void Page_Load(object sender, EventArgs e)
    {
        DataTable dt 
= new DataTable();
        dt.Columns.Add(
"c1",typeof(int));
        dt.Columns.Add(
"c2");
        dt.Rows.Add(
new object[]{11111,2});
        dt.Rows.Add(
new object[]{222222,2});this.GridView1.DataSource = dt;
        
this.GridView1.DataBind();
    }