Repeater 和 GridView 中数据格式化

GridView中显示两位小数: 

 

<asp:BoundField DataField="investmoney" DataFormatString="{0:f2}" HeaderText="投资金额">
                            <HeaderStyle />
                            <ItemStyle HorizontalAlign="Center" />
                        </asp:BoundField>

 

显示短时间:

 <asp:BoundField DataField="lendtime" DataFormatString="{0:d}" HeaderText="回款日期">
                            <HeaderStyle />
                            <ItemStyle HorizontalAlign="Center" />
                        </asp:BoundField>

 

数据是后台方法计算出来的:

 

   <asp:TemplateField HeaderText="电话">
                            <EditItemTemplate>
                                <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Mobile") %>'></asp:TextBox>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label1" runat="server"
                                    Text='<%#GetPhone(Eval("Mobile").ToString(),Eval("Phone").ToString())%>'></asp:Label>
                            </ItemTemplate>
                            <ItemStyle HorizontalAlign="Center" />
                        </asp:TemplateField>

 

 

后台方法: /// <summary>
    /// 返回有效联系电话
    /// </summary>
    /// <param name="mobile">手机字符串</param>
    /// <param name="phone">电话字符串</param>
    /// <returns></returns>
     public static string GetPhone(string mobile, string phone)
    {

        if (mobile.Trim().Length > 0 && phone.Trim().Length > 0)
        {
            return mobile.Trim().ToString();
        }
        else if (mobile.Trim().Length > 0 && phone.Trim().Length <= 0)
        {
            return mobile.Trim().ToString();
        }
        else
        {

            return phone.Trim().ToString();
        }

    }

Repeater中:数据格式:

<td><asp:Label ID="lblBackDate" Text='<%# string.Format("{0:d}",Eval("BackDate")) %>' runat="server"></asp:Label></td>
    <td><asp:Label ID="lblYieldMoney" Text='<%# string.Format("{0:f2}",Eval("YieldMoney")) %>' runat="server"></asp:Label></td>

转载于:https://www.cnblogs.com/haofaner/p/3630340.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值