您当前的位置: 首页 >  .net

[Asp.Net]如何在GridView将数字显示成金额格式或自定义格式呢?

发布时间:2009-03-11 14:23:00 ,浏览量:0

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

程序代码 程序代码
<%# toNumberGroup((int)Eval("c1")) %>

*.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();
    }
关注
打赏
1688896170
查看更多评论

暂无认证

  • 0浏览

    0关注

    106161博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.1704s