المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : link in dynamic menu



C# Programming
08-21-2009, 04:04 PM
have create a dynamic menu but problem is that how we give for a page link in clildnodes.

my code is like that---------------------------------------------

using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using System.Data.SqlClient;



public partial class top : System.Web.UI.Page

{

SqlConnection conn;

DataUtility dut = new DataUtility();

protected void Page_Load(object sender, EventArgs e)

{

PopulateMenu();

}



private void PopulateMenu()

{

DataSet ds = GetDataSetForMenu();

Menu menu = new Menu();

menu.MenuItemClick += new MenuEventHandler(menu_MenuItemClick);

foreach (DataRow parentItem in ds.Tables[0].Rows)

{

MenuItem categoryItem = new MenuItem((string)parentItem["Catname"]);

menu.Items.Add(categoryItem);

foreach (DataRow childItem in parentItem.GetChildRows("Children"))

{

MenuItem childrenItem = new MenuItem((string)childItem["Subcatname"]);

categoryItem.ChildItems.Add(childrenItem);

}

}

Panel1.Controls.Add(menu);

Panel1.DataBind();

}

void menu_MenuItemClick(object sender, MenuEventArgs e)

{

string selected = e.Item.Text;

Response.Write(selected);

}

private DataSet GetDataSetForMenu()

{

conn = dut.getConnection();

SqlDataAdapter adCat = new SqlDataAdapter("SELECT tbl_Category.* FROM tbl_Category,tbl_Usercat where tbl_usercat.uid=1 and tbl_Category.sno=tbl_Usercat.catid", conn);

SqlDataAdapter adProd = new SqlDataAdapter("SELECT tbl_SubCategory.* FROM tbl_SubCategory,tbl_UserSubcat where tbl_UserSubcat.UID=1 and tbl_SubCategory.sno=tbl_UserSubcat.SubCatid", conn);

DataSet ds = new DataSet();

adCat.Fill(ds, "tbl_Category");

adProd.Fill(ds, "tbl_SubCategory");

ds.Relations.Add("Children", ds.Tables["tbl_Category"].Columns["sno"], ds.Tables["tbl_SubCategory"].Columns["CatID"]);

return ds;

}

}





so plz help me soon.

thanks

vivek