首页 新闻 搜索 专区 学院

ASPxGridView

0
悬赏园豆:5 [已解决问题] 解决于 2010-10-14 11:44

ASPxGridView怎么格式化价格、数字呢,12.1200 怎样格式化为12.12 保留2个小数。注意 是ASPxGridView这个控件哟,不是GridView这个哟。

IT人士的主页 IT人士 | 初学一级 | 园豆:78
提问于:2010-10-07 09:38
< >
分享
最佳答案
0

看看这个示例:

效果:

标记:

 <form id="form1" runat="server">
    <div>
        <dx:ASPxGridView ID="ASPxGridView1" runat="server">
            <Columns>
                <dx:GridViewDataColumn FieldName="name">
                    <DataItemTemplate>
                        <dx:ASPxTextBox ID="txt" runat="server" Text='<%# Eval("name")%>'>
                        </dx:ASPxTextBox>
                    </DataItemTemplate>
                </dx:GridViewDataColumn>
                <dx:GridViewDataColumn FieldName="birthdate">
                    <DataItemTemplate>
                        <dx:ASPxLabel ID="lbl" runat="server" Text='<%# Eval("birthdate","{0:yyyy-MM-dd}")%>'>
                        </dx:ASPxLabel>
                    </DataItemTemplate>
                </dx:GridViewDataColumn>
                <dx:GridViewDataColumn FieldName="account">
                    <DataItemTemplate>
                        <dx:ASPxLabel ID="lbl" runat="server" Text='<%# Eval("account","{0:F2}")%>'>
                        </dx:ASPxLabel>
                    </DataItemTemplate>
                </dx:GridViewDataColumn>
            </Columns>
        </dx:ASPxGridView>
    </div>

代码:

  protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DataTable table = new DataTable();
                table.Columns.Add("name");
                table.Columns.Add("account", typeof(double));
                table.Columns.Add("birthdate", typeof(DateTime));

                DataRow row = table.NewRow();
                row["name"] = "aa";
                row["account"] = 12.123d;
                row["birthdate"] = DateTime.Now;
                table.Rows.Add(row);

                row = table.NewRow();
                row["name"] = "bb";
                row["account"] = 741.251d;
                row["birthdate"] = DateTime.Now;
                table.Rows.Add(row);

                row = table.NewRow();
                row["name"] = "cc";
                row["account"] = 124.2514d;
                row["birthdate"] = DateTime.Now;
                table.Rows.Add(row);

                row = table.NewRow();
                row["name"] = "dd";
                row["account"] = 65.1245d;
                row["birthdate"] = DateTime.Now;
                table.Rows.Add(row);

                this.ASPxGridView1.DataSource = table;
                this.ASPxGridView1.DataBind();
            }
        }

收获园豆:5
HUHU慈悲 | 大侠五级 |园豆:9973 | 2010-10-07 15:27
其他回答(1)
0

在ItemDataBound事件里面去处理。

http://www.cnblogs.com/sunyanjun/articles/1842125.html

新瓶老酒 | 园豆:181 (初学一级) | 2010-10-08 12:53
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册