如:list<string> list = new List<string>();list.add("aa");
list.add("bb");可以直接绑定到repeater吗?

解决方案 »

  1.   

    给出一个很早之前写的代码,请楼主自己观察:
    //实体类和集合,注意该集合类继承的基类using System.Collections.Generic;namespace EBShop.Model
    {
        /// <summary>
        /// 商品祖类别实体
        /// </summary>
        public class ParentCategoryInfo
        {
            #region//私有成员
            short parentCategoryID;
            string parentCategoryName;
            #endregion
            #region//公有属性
            /// <summary>
            /// 类别名称
            /// </summary>
            public string ParentCategoryName
            {
                get { return parentCategoryName; }
            }
            /// <summary>
            /// 类别编号
            /// </summary>
            public short ParentCategoryID
            {
                get { return parentCategoryID; }
            }
            #endregion
            /// <summary>
            /// 构造函数
            /// </summary>
            /// <param name="pCID">类别编号</param>
            /// <param name="pCN">类别名称</param>
            public ParentCategoryInfo(short pCID, string pCN)
            {
                this.parentCategoryID = pCID;
                this.parentCategoryName = pCN;
            }
        }
        /// <summary>
        /// 祖类别集合
        /// </summary>
        public class ParentCategoryCollection : List<ParentCategoryInfo> { }
    }
    //下面是页面中的下拉框(与你的Repeater差不多),注意控件绑定的字段是单体类的属性名称<tr>
                <td style="width: 100px">
                    所属祖类:</td>
                <td style="width: 100px">
                    <asp:DropDownList ID="DDL_ParentCategory" runat="server" DataTextField="ParentCategoryName" DataValueField="ParentCategoryID" AutoPostBack="True" OnSelectedIndexChanged="DDL_ParentCategory_SelectedIndexChanged">
                    </asp:DropDownList></td>
                <td style="width: 100px">
                    &nbsp;</td>
                <td style="width: 100px">
                    &nbsp;</td>
            </tr>
    //然后下面是业务层,就是获取类集合数据,并返回给页面层
    using System.Collections.Generic;using EBShop.Model;namespace EBShop.BLL
    {
        /// <summary>
        /// 商品祖类别业务逻辑层
        /// </summary>
        public class ParentCategory
        {
            /// <summary>
            /// 取得祖类别集合
            /// </summary>
            /// <returns>祖类别集合</returns>
            public ParentCategoryCollection GetParentCategoryList()
            {
                ParentCategoryInfo[] arryPCI ={
                    new ParentCategoryInfo(1,"消费电子"),
                    new ParentCategoryInfo(2,"日用消费品"),
                    new ParentCategoryInfo(3,"其它综合")
                };
                ParentCategoryCollection pCC = new ParentCategoryCollection();
                pCC.AddRange(arryPCI);
                return pCC;
            }
        }
    }
    //下面是页面.aspx.cs文件中给控件绑定数据源
     //祖类别
                this.DDL_ParentCategory.DataSource = new ParentCategory().GetParentCategoryList();
                this.DDL_ParentCategory.DataBind();