利用ListItem[]给DropDownList绑定数据


protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                orderstats.Items.AddRange(allstatusDDL());
                orderstats.DataBind();
                orderstats.Dispose();
            }   
        }

        /// <summary>
        /// 为dropdownlist而写的所有订单状态
        /// </summary>
        /// <returns>ListItem[]</returns>
        public ListItem[] allstatusDDL()
        {
            ListItem[] orderstatus=new ListItem[10];
            orderstatus[0] = new ListItem("所有订单", "9");
            orderstatus[1] = new ListItem("未确定","0");
            orderstatus[2] = new ListItem("已确认","1");
            orderstatus[3] = new ListItem("配货中","2");
            orderstatus[4] = new ListItem("发货中","3");
            orderstatus[5] = new ListItem("已收货","4");
            orderstatus[6] = new ListItem("未付款","5");
            orderstatus[7] = new ListItem("付款逾期","6");
            orderstatus[8] = new ListItem("已付款","7");
            orderstatus[9] = new ListItem("已取消","8");
            return orderstatus;
        }


<asp:DropDownList ID="orderstats" runat="server"></asp:DropDownList>

你可能感兴趣的:(html,C++,c,C#)