2010-02-09 6 views
0

GridView 컨트롤이 작동하도록하는 데 약간의 악영향을 미치고 있습니다. 아래 코드는 디렉토리의 모든 파일을 성공적으로 표시합니다. 그러나 나는 두 가지 변화가 필요하다. 두 가지 모두 고민 중이다.Gridview는 디렉토리의 파일 이름에 바인드되었습니다.

) 현재 URL 필드를 클릭 할 때 얻는 URL은 http://localhost/LBSExplorer/SharedUser.csv (즉, 파일 이름이있는 나의 홈 디렉토리)이다. http://mystuff/page.aspx?FileID=SharedUser.csv

B) I로 시작하는 파일을 볼 만합니다 :

내가 필요로하는 것은 '표시 텍스트'파일 이름 만, 그리고 URL이 파일 이름의 예를 들면 다음에 내 원하는 텍스트가 될 것입니다 특정 접두사 예 : "Pay". 나는 이와 비슷한 일을 할 수있다 : string [] filelist = Directory.GetFiles (@ "C : \ MF \ Data \", "Pay *. *"); 하지만 이건 내 Gridview에 바인딩하고 싶지 않다. !

나는 당신의 도움을 주셔서 감사합니다 것

!

마크

 const string DocumentFolderPhysicalPath = (@"C:\MF\Data\"); 
     const string DocumentFolderUrl = (@"C:\MF\Data\"); //"http://localhost/virtualfoldernameyouexposed/"; ; // now it is hardcoded but you could retreive it automatically 

     HyperLinkField hyperLinkField = new HyperLinkField(); 
     hyperLinkField.DataTextField = "Name"; 
     hyperLinkField.DataNavigateUrlFields = new string[] { "Name" }; 

     //Would like this to work! 
     //HyperLinkField hyperLinkField2 = new HyperLinkField(); 
     //hyperLinkField2.DataTextField = "Destination"; 
     //hyperLinkField2.DataNavigateUrlFields = new string[] { (@"C:\MF\Data\") + "Name" }; 

     GridView1.DataSource = GetDocuments(DocumentFolderPhysicalPath); 
     GridView1.Columns.Add(hyperLinkField); 
     GridView1.DataBind(); 


private System.IO.FileInfo[] GetDocuments(string physicalPath) 
{ 
    System.IO.DirectoryInfo directory = 
    new System.IO.DirectoryInfo(physicalPath); 

    if (directory.Exists) 
    { 
     return directory.GetFiles(); 
    } 
    else 
    { 
     throw new System.IO.DirectoryNotFoundException(physicalPath); 
    } 
} 

답변

1

당신이 찾고있는 것은 DataNavigateUrlFormatString 속성입니다.

hyperLinkField.DataNavigateUrlFormatString = "http://mystuff/page.aspx?FileID={0}"; 

은 {0} 여기 교체입니다 d를 DataNavigateUrlFields 값으로 설정하십시오.

+0

Yeeeeees! 나는 그것을 위해 몇 시간을 보냈다! 너는 천재 야. 너의 명예에 작은 신전을 세울거야. – Glinkot

관련 문제