私はデータソースコントロールとリストビューコントロールを持っています
データソースが持っている
"StudentID,StudentName , Birthday ,Gander(M,F),Course_ID"
listViewに表示したい
("Age -> not BirthDay, Gander(male, female)-> not f or' m, and CourseName -> not courseID :))
私はこのようにこの作業を行うためのいくつかのメソッドを書きます
public string CalculateAge(DateTime birthDate)
{
// cache the current time
DateTime now = DateTime.Today; // today is fine, don't need the timestamp from now
// get the difference in years
int years = now.Year - birthDate.Year;
// subtract another year if we're before the
// birth day in the current year
if (now.Month < birthDate.Month || (now.Month == birthDate.Month && now.Day < birthDate.Day))
--years;
return years.ToString(CultureInfo.InvariantCulture);
}
しかし、どうすれば aspx ファイルでこのメソッドを使用できますEval()
かListView
? 注: このメソッドは別の名前空間に書きました