DropDownList 的多种用法

1,与数据绑定

  1.1 静态绑定

    1.1.1在页面设计视图自己添加,或者带代码中添加

    

        <asp:DropDownList ID="DropDownList1" runat="server">
            <asp:ListItem Value="0" Text="否"></asp:ListItem>
            <asp:ListItem Value="1" Text="是"></asp:ListItem>
        </asp:DropDownList>

    1.1.2 通过绑定 List<T>或者ArrayList

    通过List<T>

//先创建Dome类
 private string id;
    private string name;

    public string Id
    {
        get { return id; }
        set { id = value; }
    }
    public string Name
    {
        get { return name; }
        set { name = value; }
    }
//从数据库得到数据
String strSql = "select id,name from empl";
DataSet ds = SqlHelper.GetDataSet(strSql);
Dome dome = new Dome();
List<Dome> list = new List<Dome>();
foreach(DataRow dr in ds.Tables[0])
{
  dome.Id = dr[0].ToString();
  dome.Name = dr[1].toString();
  list.Add(dome);
}
this.DropDownList1.DataSouce = list;
this.DropDownList1.DataBind();

 下班,未完待续。。。

posted on 2011-03-24 18:31  CodeSummer  阅读(168)  评论(0编辑  收藏  举报

导航