zoukankan      html  css  js  c++  java
  • Gridview TemplateField 显示日期

    方法一:

    代码
    <asp:TemplateField HeaderText="检查日期">           
                
    <ItemTemplate>
                    
    <%Eval("InspectionDate""{0:yyyy-MM-dd}")%>               
                
    </ItemTemplate>
            
    </asp:TemplateField>

    方法二:

    代码
    <asp:TemplateField HeaderText="检查日期">           
                
    <ItemTemplate>
                    
    <%string.Format("{0:yyyy-MM-dd}"Eval("InspectionDate")%>           
                
    </ItemTemplate>
            
    </asp:TemplateField>

    方法三:

    先在TemplateField中放一个Label控件

    代码
    <asp:TemplateField HeaderText="检查日期">           
                
    <ItemTemplate>                
                    
    <asp:Label ID="LabelInspectionDate" runat="server" Text=""></asp:Label>
                
    </ItemTemplate>
            
    </asp:TemplateField>

    然后在cs中写OnRowDataBound事件

    代码
     protected void xxxxx_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            DataRowView drv 
    = (DataRowView)e.Row.DataItem;
            
            
    if (e.Row.RowType == DataControlRowType.DataRow)
            {
                
    if (e.Row.FindControl("LabelInspectionDate"!= null)
                {
                    Label labelInspectionDate 
    = (Label)e.Row.FindControl("LabelInspectionDate");
                    labelInspectionDate.Text 
    = string.Format("{0:yyyy-MM-dd}",drv["InspectionDate"]);
                } 
            }
        }

    方法五:
    此方法和方法四有点相似,只是引用InsusDateTimeUtility自定义类别

    代码
    protected void xxxxx_RowDataBound(object sender, GridViewRowEventArgs e)
        {
        InsusDateTimeUtility  objInsusDateTimeUtility 
    = new   InsusDateTimeUtility();    
         DataRowView drv 
    = (DataRowView)e.Row.DataItem;
            
            
    if (e.Row.RowType == DataControlRowType.DataRow)
            {
                
    if (e.Row.FindControl("LabelInspectionDate"!= null)
                {
                    Label labelInspectionDate 
    = (Label)e.Row.FindControl("LabelInspectionDate");
                    labelInspectionDate.Text 
    = objInsusDateTimeUtility.GetDateTime(drv["InspectionDate"], "yyyy-MM-dd");
                } 
            }
        }
  • 相关阅读:
    CentOS上安装Mysql+PHP-fpm+Nginx
    CentOS查看端口
    QTP卷土重来之一录制脚本
    Windows Application 自动化测试之QTP卷土重来
    JAVA Appium自动化测试入门
    iOS自动化遇到坑的解决方式
    将一个字符串形式的字典转化为字典
    【python】接口测试中的异步调用
    【python】接口自动化测试中,如何校验json返回数据的格式是否正确
    【python】接口自动化测试中,json解析神器jsonpath
  • 原文地址:https://www.cnblogs.com/insus/p/1735135.html
Copyright © 2011-2022 走看看