Here we shall demonstrate how to create a drop-down list and programmatically add all the pages under the current page to the drop down list. The list will be populated in the code behind file along with the onSelectedIndexChanged handle.
<asp:DropDownList id="MyPageList" AutoPostBack="true" Width="130px" DataTextField="PageName" DataValueField="LinkURL" onSelectedIndexChanged="Selection_Change" runat="server"> </asp:DropDownList>
if (!IsPostBack) { // Add a default item to the drop down list MyPageList.Items.Add(new ListItem("Select a page", "Select a page")); // Create a page Collection PageDataCollection pdc = GetChildren (CurrentPage.PageLink); foreach (PageData page in pdc) { MyPageList.Items.Add(new ListItem(page.PageName. ToString(), page.PageName.ToString())); } }
public void Selection_Change(Object sender, EventArgs e){ PageDataCollection pdc = GetChildren(CurrentPage.PageLink); foreach (PageData page in pdc) { if(MyPageList.SelectedItem.Text == page.PageName) { Response.Redirect(page.LinkURL.ToString(), true); break; } } }
DropDownList_template.aspx code file
File that opens in a new window. If you want to download, right-click on the link and choose Save Target as...