i have datasource control and listView control
the datasource have
“StudentID,StudentName , Birthday ,Gander(M,F),Course_ID”
i want to display in my listView
(“Age -> not BirthDay,Gander(male, female)->not f or’ m, And
CourseName -> not courseID :))
i write some methods for do this work like this
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);
}
but how i can use this methods in my aspx file with Eval() in my ListView? Note: I wrote this method in a different namespace
You shouldn’t have a problem using this in a
ListView. Something like this should work:If this function is contained within a library that implements
IDisposable, you can create a pass-through function in the code-behind: