c# - Get SelectedItem's Id in dynamically generated Menu -
I've created a menu dynamically.
Here is the structure of my table:
MenuItemId integer PrimaryKey MenuItemName nvarchar (50) ParentId integer NavigateURL nvarchar (500) Here is the C # code to get that data in the heirarchical structure:
Private Zero GetMenuItems () {string cs = ConfigurationManager.ConnectionStrings ["DBCS"]. ConnectionString; SqlConnection con = new SqlConnection (CS); SqlDataAdapter da = New SqlDataAdapter ("spGetMenuData", con); Dataset ds = new dataset (); Da.Fill (DS); Forwarding (Datarov DR in Dtibles [0] .rao) {If (Dr. ["paradidied"]. Tostrings (). Trim () == "") {menu item = new menu item (); Item.Text = dr ["MenuItemName"] ToString (); Item.NavigateUrl = dr ["navigateUrl"] ToString (); ([Ds, drChild, item]] [GetChildItems (). ; }} Menu1.Items.Add (item); }}} Private Static Zero GetChildItems (DataSet DS, DataRow Dr, MenuItem Item) {MenuItem childItem = new MenuItem (); ChildItem.Text = dr ["MenuItemName"] ToString (); ChildItem.NavigateUrl = dr ["navigateUrl"]. ToString (); In the foreach (ds.Tables DataRow drChild [0] .owsows) {if (drChild ["ParentID"] ToString () == Dr. ["MenuItemID"] ToString () ..) {GetChildItems (DS, drChild, childItem) ; }} Item.ChildItems.Add (childItem); } Here's my HTML:
& Lt; DynamicManUItemstyle Horizontal Padding = "15px" Vertical Padding = "10px" /> & Lt; Dynamic Menu Back Backlor = "# 99ff99" /> & Lt; Style Selective BackAcllor = "Green" /> with Dynamic & Lt; StaticHoverStyle BackColor = "Blue" ForeColor = "White" /> & Lt; StaticMenuItemStyle horizontal pinning = "10px" vertical padding = "10px" /> & Lt; StaticMenuStyle BackColor = "# ff6699" /> & Lt; Static SelelectStyle BackColor = "Green" /> & Lt; / ASP: Menu & gt; Now I have to get the menu item selected from that menu.
Can anyone tell me how do I get it?
Thank you.
It should do this.
string s = Menu1.SelectedValuePath = ID;
Comments
Post a Comment