Click to See Complete Forum and Search --> : how to bind a dropdownlist within a datalist


jarrodlytle
08-16-2005, 11:05 AM
I have a datalist that is bound to a dataset. I need to bind a dropdownlist in the datalist to a different datasource.

haven't been able to figure it out :(

any help would be greatly appreciated!

A1ien51
08-16-2005, 12:12 PM
The basic idea is here:

<EditItemTemplate>
<asp:DropDownList ID="ddlID" Runat="Server" DataTextField="Something" DataValueField="SomethingElse" DataSource="<%# GetOptions() %>"></asp:dropdownlist>
</EditItemTemplate>

and the server side code

Function GetOptions() as DataTable
'Run your SQL statement and return your datatable
End Function

Eric

jarrodlytle
08-17-2005, 12:12 AM
Thanks alot. That helps but know i need to know something else.

Im trying to bind the dropdownlist to Directoryinfo.

heres the code im trying to bind.


Dim d1 As DirectoryInfo = New DirectoryInfo(server.mappath("\Files\"))
dropdownlist.DataSource = d1.GetFiles()
dropdownlist.DataBind()


Thats how i bind it outside if a datalist.

how can i conform this to your getoptions() function?


thanks in advance!!

A1ien51
08-17-2005, 06:58 AM
Function GetOptions() as ???????
Dim d1 As DirectoryInfo = New DirectoryInfo(server.mappath("\Files\"))
Return d1.GetFiles()
End Function

Do not have VS open so I am not sure what ????? is for GetFiles()

Eric

jarrodlytle
08-17-2005, 10:50 AM
thanks a lot, cured my headache :D

A1ien51
08-17-2005, 11:03 AM
Glad I could help....