2014-12-19 68 views
-1

編程菜單項我想禁用或啓用我從數據庫用戶菜單欄,我已經做了父母的菜單項,但我也想禁用或啓用的子菜單項,這裏是我的代碼禁用或啓用從數據庫

StrSql = "Select serial_no,optionName,MenuID from [User_" + Session["UserEmail"] + "]"; 

StrSql = StrSql + " Order By serial_no"; 

DataSet rs = (DataSet)MethodClass.ConnectionToQuery(StrSql); 

if (rs.Tables[0].Rows.Count > 0) 
{ 
    for (i = 0; i < MnuUserManagement.Items.Count; i++) 
    { 

     StrOpt = MnuUserManagement.Items[i].Text.ToString(); 

     if (StrOpt != "-" || StrOpt == "") 
     { 
      for (j = 0; j < rs.Tables[0].Rows.Count ; j++) 
      { 

       if (StrOpt == rs.Tables[0].Rows[j]["optionName"].ToString()) 
       { 
        MnuUserManagement.Items[i].Enabled = true; 
       } 
      } 
     } 
    } 
} 
+0

請出示創建菜單您的數據庫表結構?還有一些標記。請參閱本:HTTP://www.codingfusion.com/Post/Multilevel-Dynamic-CSS3-Dropdown-Menu-in-asp-net – 2014-12-19 10:35:18

回答

0

StrSql =「從[User_」+ Session [「UserEmail」] +「]」選擇serial_no,optionName,MenuID; StrSql = StrSql +「Order By serial_no」; 數據集rsmenu =(數據集)MethodClass.ConnectionToQuery(STRSQL); 如果(rsmenu.Tables [0] .Rows.Count> 0){

   for (var i = 0; i < rsmenu.Tables[0].Rows.Count; i++) 
       { 
        foreach (MenuItem item in MnuUserManagement.Items) 
        { 
     if (item.Text == rsmenu.Tables[0].Rows[i]["optionName"].ToString()) 
         { 
          item.Enabled = true; 

//這裏我啓動子爲菜單項 STRSQL一個新的數據集=「選擇serial_no,OPTIONNAME,MENUID從[用戶_ 「+ Session [」UserEmail「] +」]「; StrSql = StrSql +「Order By serial_no」; 數據集RS =(數據集)MethodClass.ConnectionToQuery(STRSQL);

 if (rs.Tables[0].Rows.Count > 0) 
     { 
      for (var i = 0; i < rs.Tables[0].Rows.Count; i++) 
      { 

       foreach (MenuItem childItem in item.ChildItems) 
       { 
      if (childItem.Text == rs.Tables[0].Rows[i]["Optionname"].ToString()) 
        { 
         childItem.Enabled = true; 
        } 
       } 
      } 
     } 
         } 
        } 
       } 

      }