2012-05-07 2 views
0

내가 데이터 소스 컨트롤과 ListView 컨트롤을 가지고와 영문 파일에 매개 변수로 평가()를 사용하는 방법을내가 ListView에

데이터 소스가

"StudentID, StudentName, 생일, 아내와 별거중인 남편 (M, F) >되지 생일, 아내와 별거중인 남편 (남성 -, 나이 "

내가 내 목록보기

(에 표시 할"Course_ID에 여성) -> F 또는 'm, 그리고 CourseName하지 ->하지 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); 
     } 

같은이 일을 위해

내가 몇 가지 방법을 쓰기하지만 난 방법을 사용할 수 있습니다 내 ListViewEval() 내 aspx 파일 에서이 방법은? 참고 :이 메서드를 다른 네임 스페이스에 썼습니다.

답변

2

ListView에서이 방법을 사용하면 안됩니다. 이런 식으로 뭔가 작업을해야합니다 :

public string CalculateAge(DateTime birthDate) 
{ 
    using (var obj = new MyObject()) 
    { 
     return obj.CalculateAge(birthDate); 
    } 
} 
+0

덕분에 제임스하지만 약 :이 기능을 IDisposable를 구현하는 라이브러리에 포함되어

<%# CalculateAge((DateTime)Eval("SomeDate")) %> 

경우, 통과 코드 숨김 기능을 만들 수 있습니다 서로 다른 네임 스페이스의 내 메서드가 – tito11

+0

인 경우 해당 네임 스페이스에 페이지에 액세스 할 수 있습니까? 코드 숨김에서 액세스 할 수 있습니까? –

+0

예 code-behing에서 액세스 할 수 있습니다. 지금 시도하십시오. – tito11