public DropDownList FileList(string FolderName,string FileType)
{
DropDownList List = new DropDownList();
try
{
DirectoryInfo dirinfo = new DirectoryInfo(FolderName);
FileInfo[] myfolders = dirinfo.GetFiles(FileType);
foreach (FileInfo myfolder in myfolders)
{
List.Items.Add(myfolder.Name);
}

catch{}
return List;
}
DropDownList3=FileList(mapPath,"*.htm");???????????????、
这个DropDownList3是手工建的怎么才能让它等于FileList()的返回值。
现在这么直接=没有值

解决方案 »

  1.   

    public void FileList(ref DropList dl, string FolderName,string FileType)
    {
    try
    {
    DirectoryInfo dirinfo = new DirectoryInfo(FolderName);
    FileInfo[] myfolders = dirinfo.GetFiles(FileType);
    foreach (FileInfo myfolder in myfolders)
    {
    dl.Items.Add(myfolder.Name);
    }

    catch{}
    }
    FileList(DropDownList3, mapPath, "*.htm");
      

  2.   

    Sorry, public void FileList(ref DropDownList dl ......
      

  3.   

    楼上的可以
    但是修改一下
    public void FileList(ref DropDownList dl, string FolderName,string FileType)
    {..}
    FileList(ref DropDownList3, mapPath, "*.htm");
      

  4.   

    谢谢两位,over了。请问一下这个ref DropDownList dl是怎么回事。
      

  5.   

    msdn上说的很清晰
    ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/csref/html/vclrfRef.htm
      

  6.   

    ref就是地址传递嘛,对象是在堆上。
      

  7.   

    ref是引用传参,对引用参数的修改就等于对实参的修改。
    其实DropDownList本身是个引用类型不加ref也可以的。