zoukankan      html  css  js  c++  java
  • 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>

  • 相关阅读:
    11个重要的数据库设计规则
    CentOS 6.8 新安装系统的网络IP配置(转载)
    WebView根据加载的内容来控制其高度
    遗传算法
    Selenium: Trying to log in with cookies and get the errorMessage
    用Tesseract训练验证码遇到的问题
    利用jTessBoxEditor工具进行Tesseract-OCR样本训练
    Tesseract处理背景渐变的图片
    XPath语法
    在Python中用Selenium执行JavaScript
  • 原文地址:https://www.cnblogs.com/haofaner/p/3630340.html
Copyright © 2011-2022 走看看