Dropdownlists in DetailsView
I am creating a site based on TheBeerHouse concepts and am developing a page similar to Admin/AddEditArticle.aspx. I want to include an 'Albums' dropdownlist and a 'Photos' dropdownlist on the page. The selectedvalue from Albums is used as a key to populate the following 'Photos' dropdownlist.
In my BLL.Articles.Article class, I add four properties similar to the CategoryID and CategoryTitle fields: AlbumID, AlbumCaption, PhotoID and PhotoCaption. AlbumID is a foreign key in Articles to an Albums class; PhotoID is a foreign key in Articles to a Photos class. The Photos class contains a foreign key AlbumID to the Albums class.
My Article class contains:
ID
CategoryID
CategoryTitle
AlbumID
AlbumTitle
PhotoID
PhotoTitle
...
My Album class contains:
AlbumID
AlbumCaption
My Photo class contains:
PhotoID
AlbumID
PhotoCaption
PhotoUrl
In the database, the Articles table contains
ArticleID
CategoryID
AlbumID
PhotoID
...
The Albums table contains
AlbumID
AlbumCaption
The Photos table contains
PhotoID
AlbumID
PhotoCaption
PhotoUrl
When editing an Article in Admin/AddEditArticle, I have successfully added an ItemTemplate with a dropdownlist that allows the user to choose an Album from the list of Albums by displaying a list of AlbumCaptions that are bound to AlbumIDs.
I then want to have a dropdown list of PhotoCaptions for Photos that is filtered based on the AlbumID selected above. (Actually, will be populated using a query of photos WHERE AlbumID=x.)
I am using ObjectDataSources throughout my app and have created all of the necessary BLL and DAL code. I am relatively new to .NET, however, and am struggling with the User Interface code.
The AddEditArticle detailview includes the following Album template:
<asp:TemplateField HeaderText="Album"
InsertVisible="False" SortExpression="AlbumID">
<ItemTemplate>
<asp:Label ID="lblAlbum" runat="server"
Text='<%# Eval("Caption") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddlAlbums" runat="server"
DataSourceID="objAllAlbums" DataTextField="Caption"
DataValueField="AlbumID"
SelectedValue='<%# Bind("AlbumID") %>' Width="100%">
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
Once the user selects, the appropriate AlbumID, I then want to populate a dropdown list of the PhotoCaptions of the Photos associated with the selected Album.
I assume I need to handle a ddlAlbums_SelectedIndexChanged event, set a value in the detailsview, and then call databind.
I then need to create a DataSource that allows me to call my the GetPhotos method of my Photo BLL class, supplying the selected AlbumID as a parameter.
I've tried a number of combinations, but none of them have worked. Suggestions?
I assume I need something similar to this:
<asp:ObjectDataSource ID="objPhotosByAlbum" runat="server"
SelectMethod="GetPhotos" TypeName="PhotoManager">
<SelectParameters>
<asp:ControlParameter ControlID="ddlAlbums"
Name="albumID" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
Is ControlParameter the correct control? Or simply a Parameter control? How do I map the selectedvalue from the ddlAlbums control to act as input to the ddlPhotos control?
Thanks for any assistance!
Kevin
|