Dear All

I have 2 dropdown lists. One containing the Main Menus, and the other one containing the relevant sub menus. Ie when I change the first drop down list, I want the second one the get the correct Menu ID and change accordingly to display the Sub Menu list. Everything is working fine, until i am trying to edit an entry.

My problem is that when I am editing an entry I am not getting the ID stored in the database, so the Sub Menu list initially is not set to the particular Sub Menu ID that there is in the database. Can you please tell me how I can get this ID and set the drop down list to automatically reflect that sub menu ID and display it.

Here is my code at the moment:-

<tr>
<td>
Main Menu
</td>
<td>
<aspropDownList ID="ddlMainPage" runat="server" DataSourceID="dsAdminMainMenus" DataTextField="admin_menu_tit" DataValueField="admin_menu_id"
AutoPostBack="True" EnableViewState="False" OnDataBinding="ddlMainPage_DataBound">
<asp:ListItem>-- Select --</asp:ListItem>
</aspropDownList>
<asp:RequiredFieldValidator ID="rfvddlMainPage" runat="server" ControlToValidate="ddlMainPage"
ErrorMessage="Please Select" InitialValue="-- Select --"></asp:RequiredFieldValidator>
<asp:ObjectDataSource ID="dsAdminMainMenus" runat="server" SelectMethod="GetAdminMainMenus"
TypeName="MenusBLL">
<SelectParameters>
<asp:Parameter Name="DataSource" DefaultValue="Hamrun_DB" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
</td>
</tr>
<tr>
<td>
Sub Menu
</td>
<td>
<aspropDownList ID="ddlSubPage" runat="server" DataSourceID="dsAdminSubMenus" DataTextField="admin_submenu_tit" DataValueField="admin_submenu_id" EnableViewState="False">
</aspropDownList>
<asp:RequiredFieldValidator ID="rfvddlSubPage" runat="server" ControlToValidate="ddlSubPage"
ErrorMessage="Please choose a Sub Menu here" SetFocusOnError="True" InitialValue="Select">
</asp:RequiredFieldValidator>
<asp:ObjectDataSource ID="dsAdminSubMenus" runat="server" SelectMethod="GetAdminSubMenus"
TypeName="MenusBLL">
<SelectParameters>
<asp:Parameter Name="DataSource" DefaultValue="Hamrun_DB" Type="String" />
<asp:ControlParameter ControlID="ddlMainPage" DefaultValue="" Name="fk_admin_menu_id" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
</td>
</tr>


and the cs:-

protected void ddlMainPage_DataBound(object sender, EventArgs e)
{
DropDownList ddlMainPage = (DropDownList)sender;

if (formHeader.CurrentMode == FormViewMode.Edit)
{
//get the selected value
((this.formHeader.FindControl("ddlMainPage") as DropDownList).SelectedValue) = this.formHeader.DataKey["fk_admin_menu_id"].ToString();
}
}

Thanks for your help and time

Johann