|
本帖最后由 szjazz 于 2014-3-8 21:59 编辑
现在有个疑惑,编了一个树菜单的类,但相应的菜单项点击的事件,在引用类的页面会有所不同,所以,想将点击的事件先在引用的页面写法,想作为类的属性传递到类,不知如何实现?
动态从数据库读取生成菜单:
树形菜单类的代码
- public void LoadMenu(DataTable dt)
- {
- if (dt.Rows.Count == 0)
- return;
- // 原理:根据父子字段建立父表与子表的相互关系
- //显示每一个第一个父结点,再调用递归ResolveSubTree显示该父记录下的所有子记录
- DataSet ds = new DataSet();
- ds.Tables.Add(dt);
- if (fNameId != fNamePId)
- //如果父子字段相同,则不存在父子表的关系
- ds.Relations.Add("TreeRelation", ds.Tables[0].Columns[fNameId], ds.Tables[0].Columns[fNamePId], false);
- DbTypeOfColumn = dt.Columns[fNameId].DataType.Name;
- DataRow[] drArray;
- //如果数据源记录包含根结点(其值为空或等于0)
- if (ContainParent)
- drArray = dt.Select("ParentId is null or ParentId=0");
- else
- drArray = dt.Select();
- //
- if (CategoryMenu == null)
- NodeIdPreWord = "Sys";
- else
- NodeIdPreWord = CategoryMenu.ID;
- //通过反射获取属性Menus
- PropertyInfo menuInfo = CategoryMenu.GetType().GetProperty("Menu");
- FineUI.Menu menu = menuInfo.GetValue(CategoryMenu, null) as FineUI.Menu;
- Temp temp=new Temp();//引入模板数据规范
- foreach (DataRow row in drArray)
- {
- FineUI.MenuButton mbtnMenu = new MenuButton();
- string nodeText = row[fNameText].ToString();
- string nodeId = row[_fNameId].ToString();
- mbtnMenu.ID = NodeIdPreWord + nodeId;
- mbtnMenu.Text = nodeText;
- mbtnMenu.EnablePostBack = true;
- //如果是针对表格的菜单按钮,还须判断是否有选择项
- if (grid != null)
- {
- if (Action != "addnew" || string.IsNullOrEmpty(Action))
- mbtnMenu.OnClientClick = grid.GetNoSelectionAlertInParentReference(Grid.noSelectionMessage);
- }
- mbtnMenu.Click += new EventHandler(temp.DataRuleTemp);//就在这儿,不知如何传递???
- menu.Items.Add(mbtnMenu);
-
- if (fNameId != fNamePId)
- ResolveSubMenu(row, mbtnMenu);
- }
- }
-
- /// <summary>
- /// 将树项绑定到菜单按钮
- /// </summary>
- /// <param name="btn"></param>
- /// <param name="nodes"></param>
- public void ResolveSubMenu(DataRow dataRow,ControlBase btn)
- {
- //FineUI.Menu menu = new Menu();
- //// 通过反射获取属性Menus
- //PropertyInfo info = btn.GetType().GetProperty("Menus");
- //(info.GetValue(btn, null) as MenuCollection).Add(menu);
- DataRow[] drArray = dataRow.GetChildRows("TreeRelation");
- PropertyInfo menuInfo = btn.GetType().GetProperty("Menu");
- FineUI.Menu menu = menuInfo.GetValue(btn, null) as FineUI.Menu;
- Temp temp = new Temp();//引入模板数据规范
- foreach (DataRow row in drArray)
- {
- FineUI.MenuButton mbtnMenu = new MenuButton();
- string nodeText = row[fNameText].ToString();
- string nodeId = row[_fNameId].ToString();
- mbtnMenu.ID = NodeIdPreWord + nodeId;
- mbtnMenu.Text = nodeText;
- mbtnMenu.EnablePostBack = true;
- //如果是针对表格的菜单按钮,还须判断是否有选择项
- if (grid != null)
- {
- if (Action != "addnew" || string.IsNullOrEmpty(Action))
- mbtnMenu.OnClientClick = grid.GetNoSelectionAlertInParentReference(Grid.noSelectionMessage);
- }
- mbtnMenu.Click += new EventHandler(temp.DataRuleTemp);;//就在这儿,不知如何传递???
- menu.Items.Add(mbtnMenu);
- if (row.GetChildRows("TreeRelation").Length > 0)
- {
- ResolveSubMenu(row,mbtnMenu);
- }
- }
- }
复制代码
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
|