Need help populating a DropDownList in and EditItemTemplate

I have a dropdownlist that I have in an EditItemTemplate that I need to populate with a list of files in a directory on my web server.

Currently, this is how I'm retrieving the file names:

DirectoryInfo dir = new DirectoryInfo(@"e:\web\xxx\htdocs" + strPath);

FileInfo[] bmpfiles = dir.GetFiles("*.*");

foreach( FileInfo f in bmpfiles)

{

ddl.Items.Add(f.Name);

lblMessage.Text += "Name is: " + f.Name + "<br>";

}

From my web form I am calling this class, passing in a path (directory name), the DropDownList I want to add the items to, and then a Label to see the output for testing.

Is this the right approach Or should I build a dataset with the file names then do the DataBinding in the Control code



Answer this question

Need help populating a DropDownList in and EditItemTemplate

  • jandrews

    Thanks for your attention to my question. I actually just created a datatable and stuffed the File IO data into it. It wasn't that difficult, just didn't know if there was another way since there are always a million ways to do things.

    Thanks again


  • Eivind__no09

    This actually appears to be an ASP.NET application; the question would be better asked at the ASP.NET forums (www.asp.net/forums). I am moving the post back to the data access forum, as it certainly is more relevant there than in the windows forms forum.

    It depends on what your are trying to do with this list of files. Building a DataSet is probably overkill; you might try setting the DataSource of the DropDownList to the FileInfo array, and setting the DisplayMember and ValueMember to "Name".



  • KrishnaKumar Sivasubramanian

    One more issue, here. When I try to populate the DropDownList that is in the EditItem Template, VB does not seem to be able to find the list within the template. For example, DropDownList1.DataSource gives an error. And GridView1.DropDownList1.DataSource does not work either.
  • John Maloney

    While you are considering DataSet for storage, this question is primarily about manipulating UI controls, and should be asked in the Windows Forms forums. I'll move the thread.


  • Need help populating a DropDownList in and EditItemTemplate