一个二级MENU绑定例子: private void Menu(string strMainId, string strYear) { DataTable menuData = GetMenuDate(strYear); DataTable menuChildData = GetChildMenuDate(strMainId); AddTopMenuTop(menuData,menuChildData); } private DataTable GetChildMenuDate(string strMainid)//string Bu, string Department, string OfficeName, string Year) { //string strSql = "SELECT DISTINCT PERID,PERSPECTIVE,CRIID,CRITICALITEM,MainId FROM VIEW_KPIINF WHERE BU='" + Bu + "' AND SUPDEP='" + Department + "' AND DEP='"+OfficeName+"' AND YEAR='" + Year + "'"; string strSql = "SELECT DISTINCT PERID,PERSPECTIVE,CRITICALITEM FROM VIEW_KPIINF WHERE MAINID='" + strMainid + "'"; SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]); SqlDataAdapter da = new SqlDataAdapter(strSql, con); DataSet ds = new DataSet(); da.Fill(ds, "View_KPIINF"); DataTable DT = ds.Tables[0]; return DT; } private DataTable GetMenuDate(string strYear) { string strSql = "SELECT DISTINCT PERID,PERSPECTIVE FROM KPI_PERSPECTIVE WHERE YEAR='" + strYear + "' Order by PerID Asc"; SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]); SqlDataAdapter da = new SqlDataAdapter(strSql, con); DataSet ds = new DataSet(); da.Fill(ds, "View_KPIINF"); DataTable DT = ds.Tables[0]; return DT; } private void AddTopMenuTop(DataTable menuData,DataTable ChildMenuData) { DataView view = new DataView(menuData); DataView viewchild=new DataView(ChildMenuData); foreach(DataRowView row in view) { MenuItem newMenuItem=new MenuItem(row["Perspective"].ToString(),row["PerID"].ToString()); Menu1.Items.Add(newMenuItem); AddChildMenu(ChildMenuData, newMenuItem); } } private void AddChildMenu(DataTable ChildMenuData, MenuItem parentMenuItem) { DataView view = new DataView(ChildMenuData); view.RowFilter = "perid=" + parentMenuItem.Value; foreach (DataRowView row in view) { MenuItem newMenuItem = new MenuItem(row["CRITICALITEM"].ToString(), row["CRITICALITEM"].ToString()); parentMenuItem.ChildItems.Add(newMenuItem); } }