我正在尝试在Web窗体中动态创建菜单,但出现了populatin子项问题。这是我的代码
DataSet ds = new DataSet();
DataTable dt = new DataTable();
Delivery_SettingDAL delivery_SettingDAL = new Delivery_SettingDAL();
ds = delivery_SettingDAL.get_menu_Items();
dt = ds.Tables[0];
foreach(DataRow item in dt.Select("PerentID=" + 0))
{
MainMenu.Items.Add(new MenuItem(item["menuname"].ToString(), item["MenuID"].ToString(), "", item["Menulocation"].ToString()));
}
foreach (DataRow item in dt.Select("PerentID>" + 0))
{
MenuItem men1 = new MenuItem(item["menuname"].ToString(), item["MenuID"].ToString(), "", item["Menulocation"].ToString());
MainMenu.FindItem(item["perentid"].ToString()).ChildItems.Add(men1);
我遇到此异常System.Web.UI.WebControls.Menu.FindItem(...)在此行返回空强文本
MainMenu.FindItem(item["perentid"].ToString()).ChildItems.Add(men1);
我不知道为什么。
这是我的delivery_SettingDAL.get_menu_Items();
private const string PK_GET_MENU_ITEMS = "SELECT MENUID,MENUNAME,MENULOCATION,PERENTID FROM MENU";
public DataSet get_menu_Items()
{
DataSet ds = new DataSet();
using (OracleConnection oracleConnection = new OracleConnection())
{
try
{
oracleConnection.ConnectionString = ConfigurationManager.ConnectionStrings["DataBase"].ToString();
oracleConnection.Open();
OracleDataAdapter oracleDataAdapter = new OracleDataAdapter(PK_GET_MENU_ITEMS, oracleConnection);
oracleDataAdapter.Fill(ds);
}
catch (OracleException ex)
{
IDelivery_Setting delivery_Setting = new Delivery_SettingDAL();
delivery_Setting.AddExeption(ex.ToString(), "UsersDAL", "VerifyUserID");
}
finally
{
oracleConnection.Close();
}
}
return ds;
}