using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using OAModels;
using OABLL;public partial class admin_ShowUser : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindTreeView();
        }
    }
//用于动态绑定树的方法
    private void BindTreeView()
    {
        IList<BranchInfo> branchInfo = BranchInfoManager.GetALLBranchInfo();
        foreach (BranchInfo bi in branchInfo)
        {
            TreeNode fatherNodes = new TreeNode();
            fatherNodes.Text = bi.BranchName;
            fatherNodes.Value = null;
            fatherNodes.ImageUrl = "images/menuclose.gif";            //向树加根节点
            this.TreeView1.Nodes.Add(fatherNodes);
            ////NEW支节点实例
            IList<DepartInfo> depaertInfoChild = TreeNodeManager.GetDepartInfoChildNodesBySql(bi.BranchId);            foreach (DepartInfo diChild in depaertInfoChild.DepartInfo)
            {
................
运行报错为IList<OAModels.BranchInfo>不包含"GetEnumerator"的公共定义因此foreach语句不能作用于IList<OAModels.BranchInfo>类型变量
          IList<OAModels.DepartInfo>不包含不包含"GetEnumerator"的公共定义因此foreach语句不能作用于IList<OAModels.DepartInfo>类型变量
我该怎么改,谢谢,问题解决立刻结贴,望指教
        

解决方案 »

  1.   

    把泛型集合转换为DataTable再使用 #region 泛型集合转换为DataTable
        /// <summary>
        ///  Ilist<T> 转换成 DataTable
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="i_objlist"></param>
        /// <returns></returns>
        public static DataTable ConvertToDataTable<T>(IList<T> i_objlist)
        {
            if (i_objlist == null || i_objlist.Count <= 0)
            {
                return null;
            }
            DataTable dt = new DataTable(typeof(T).Name);
            DataColumn column;
            DataRow row;        System.Reflection.PropertyInfo[] myPropertyInfo = typeof(T).GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);        foreach (T t in i_objlist)
            {
                if (t == null)
                {
                    continue;
                }            row = dt.NewRow();            for (int i = 0, j = myPropertyInfo.Length; i < j; i++)
                {
                    System.Reflection.PropertyInfo pi = myPropertyInfo[i];                string name = pi.Name;                if (dt.Columns[name] == null)
                    {
                        column = new DataColumn(name, pi.PropertyType);
                        dt.Columns.Add(column);
                    }                row[name] = pi.GetValue(t, null);
                }            dt.Rows.Add(row);
            }
            return dt;
        }
        #endregion