• 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");
                } 
            }
        }
  • 相关阅读:
    win7系统内网共享打印机设置
    VS中无法打开Qt资源文件qrc
    EF开发中EntityFramework在web.config中的配置问题
    【转】为什么你的硬盘容易坏?因为它转得实在是太快了
    AutoCAD批量导出点坐标
    【读书】《当我跑步时,我谈些什么》书评:我跑步时,只是跑着
    【C/C++】How to execute a particular function before main() in C?
    【gdb】A brief introduction on how to use gdb
    【Valgrind】How to check if we reading uninitialized memory in 10 min
    【Valgrind】How to check buffer overflow/underflow in 10 mins
  • 原文地址:https://www.cnblogs.com/insus/p/1735135.html
Copyright © 2020-2023  润新知