绑定模板列,前台代码如下:
<asp:TemplateField HeaderText="登录日期" ItemStyle-Width="70px">
                        <ItemTemplate>
                            <asp:Label ID="txtlogindate" runat="server" Text='<%#TimeToDateStr(Eval("login_time").ToString(),"","","") %>'></asp:Label>
                        </ItemTemplate>
                        <ItemStyle Width="70px"></ItemStyle>
                    </asp:TemplateField>上文中,Text中的TimeToDateStr为自定义函数,原本这个函数是写在一个单独的类文件中的,实际测试发现只能写在本身的后台代码文件中才能正常使用,请问如何在Text中调用其他类中的函数?

解决方案 »

  1.   

    <div class="date">
    <%# Jnd.Utility.CommonFuntion.getDate(Eval("inputdate").ToString()) %>
    </div>using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Data;
    using System.Data.SqlClient;namespace Jnd.Utility
    {
        public class CommonFuntion
        {
           
      public static string getDate(string dt)
            {
                try
                {
                    DateTime time = Convert.ToDateTime(dt);
                    return time.ToString("MM-dd");
                }
                catch
                {
                    return "";
                }
            }
        }
    }