当前位置:编程学习 > asp >>

Asp.net常用的操作函数

/// <summary>
        /// 取得本周第一天的日期,即星期日
        /// </summary>
        /// <returns></returns>
        public static string GetWeekFirstDate()
        {
            return DateTime.Now.AddDays(Convert.ToDouble((0 - Convert.ToInt16(DateTime.Now.DayOfWeek)))).ToShortDateString();

        }

        /// <summary>
        /// 取得本周最后一天的日期
        /// </summary>
        /// <returns></returns>
        public static string GetWeekLastDate()
        {
            return DateTime.Now.AddDays(Convert.ToDouble((6 - Convert.ToInt16(DateTime.Now.DayOfWeek)))).ToShortDateString();
        }

        /// <summary>
        /// 转换成Long型,错误返回-1
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static long ConvertToLong(object value)
        {
            long id = -1;
            long.TryParse(value.ToString(), out id);
            return id;
        }
        /// <summary>
        /// 转换成Double型,错误返回-1
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static double ConvertToDouble(object value)
        {
            double id = -1;
            double.TryParse(value.ToString(), out id);
            return id;
        }

        /// <summary>
        /// 转换成Int型,-1转换错误
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static int ConvertToInt(object value)
        {
            int id = -1;
            int.TryParse(value.ToString(), out id);
            return id;
        }
        /// <summary>
        /// 绑定数据到ListControl
        /// </summary>
        /// <param name="lc"></param>
        /// <param name="dt"></param>
        /// <param name="strText"></param>
        /// <param name="strValue"></param>
        public static void BindDrop(ListControl lc, DataTable dt, string strText, string strValue)
        {
            lc.Items.Clear();

            foreach (DataRow myRow in dt.Rows)
            {
                lc.Items.Add(new ListItem(myRow[strText].ToString(), myRow[strValue].ToString()));
            }
            lc.DataBind();
        }

        /// <summary>
        /// 绑定数据到ListControl
        /// </summary>
        /// <param name="lc"></param>
        /// <param name="dt"></param>
        /// <param name="strText"></param>
        /// <param name="strValue"></param>
        public static void BindDrop(ListControl lc, DataTable dt, string strText, string strValue, string FirstText, string FirstValue)
        {
            lc.Items.Clear();
            lc.Items.Add(new ListItem(FirstText, FirstValue));
            foreach (DataRow myRow in dt.Rows)
            {
                lc.Items.Add(new ListItem(myRow[strText].ToString(), myRow[strValue].ToString()));
            }
            lc.DataBind();
        }

        /// <summary>
        /// 绑定数据到ListControl
        /// </summary>
        /// <param name="lc"></param>
        /// <param name="FirstText"></param>
        /// <param name="FirstValue"></param>
        public static void BindDrop(ListControl lc, string FirstText, string FirstValue)
        {
            lc.Items.Clear();
            lc.Items.Add(new ListItem(FirstText, FirstValue));
            lc.DataBind();
        }
        public static void BindDataDrop(ListControl list, int iBegin, int iEnd)
        {
    &

补充:Web开发 , ASP.Net ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,