Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Add a Tree Menu to DataGrid Header Text

, 9 Nov 2005 CPOL
This article shows how to add a JavaScript tree menu to a DataGrid head text.
using System;

namespace DataGridWithTreeMesu
{
	/// <summary>
	/// Summary description for DateTime.
	/// </summary>
	public class MyDateTime
	{
		public MyDateTime()
		{
			//
			// TODO: Add constructor logic here
			//
		}

		/// <summary>
		/// JulianToGregorian
		/// </summary>
		/// <PARAM name="strGregDate">string</PARAM>
		/// <PARAM name="strFormat">string</PARAM>
		public string JulianToGregorian(string strGregDate, string strFormat)
		{
			DateTime dtStart; 
			DateTime dtTrms;	 
			int iDays;	 
			int iYear;	 		 
			string strDate;
			int iPos;
			Array arParams = null;
			 
			strFormat = strFormat.ToUpper();
			arParams = strGregDate.Split('.');
			iYear = Convert.ToInt32((arParams.GetValue(0)).ToString());
			iDays = Convert.ToInt32((arParams.GetValue(1)).ToString());
			dtStart = new DateTime(iYear, 1, 1);
			dtTrms = dtStart.AddDays(iDays - 1);
			strDate = dtTrms.ToString();
			iPos = strDate.IndexOf(' ');
			strDate = strDate.Substring(0, iPos);

			strDate = ChangeDateFormat(strDate, strFormat);
			return strDate;
		}

		/// <summary>
		/// ChangeDateFormat
		/// </summary>
		/// <PARAM name="strDate">string</PARAM>
		/// <PARAM name="strFormat">string</PARAM>
		public string ChangeDateFormat(string strDate, string strFormat)
		{
			DateTime dateToInsert;
		 
			try
			{
				dateToInsert = DateTime.Parse(strDate);
			}
			catch
			{
				dateToInsert = DateTime.MinValue;
			}

			strFormat = strFormat.ToUpper();
			if(strFormat.StartsWith("MM") && strFormat.IndexOf("YYYY") != -1)
				strDate = dateToInsert.ToString("MM/dd/yyyy");
			else
				if(strFormat.StartsWith("MM") && strFormat.IndexOf("YY") != -1)
				strDate = dateToInsert.ToString("MM/dd/yy");
			else
				if(strFormat.StartsWith("DD") && strFormat.IndexOf("YYYY") != -1)
				strDate = dateToInsert.ToString("dd/MM/yyyy");
			else
				if(strFormat.StartsWith("DD") && strFormat.IndexOf("YY") != -1)
				strDate = dateToInsert.ToString("dd/MM/yy");

			return strDate;
		}


	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Florence FZ Li
Web Developer
United States United States
M.S.: Computer Science, B.S.: Physics, MCSD: .NET, MCSD: VS 6
 
Florence currently works at Confident Software, Inc. Atlanta, U.S.A. Besides programming, during her spare time she enjoys opera.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141220.1 | Last Updated 9 Nov 2005
Article Copyright 2005 by Florence FZ Li
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid