.NET 程序花园

光说不练那是花把式,照不住。光练不说那是在自我陶醉,心要有数。 ~^_^~

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

                                           DropDownList 绑定方法总结

                                       

方法一:

string Sql = "SELECT RoleName FROM Roles";

                     Database db = DatabaseFactory.CreateDatabase("DataConsole");

                     DBCommandWrapper dbc = db.GetSqlStringCommandWrapper(Sql);          

                     DataSet ds = db.ExecuteDataSet(dbc);

                     this.DropDownList2.DataSource=ds.Tables["Roles"];

                     string[] s=new string[ds.Tables[0].Rows.Count];

                     for(int i=0;i<s.Length;i++)

                     {

                            s[i]=ds.Tables[0].Rows[i].ItemArray[0].ToString();

                     }

                     foreach(string ss in s)

                     {

                            DropDownList2.Items.Add(ss);

}

 

方法二:

 

            string Sql = "SELECT RoleName FROM Roles";

                     Database db = DatabaseFactory.CreateDatabase("DataConsole");

                     DBCommandWrapper dbc = db.GetSqlStringCommandWrapper(Sql);          

                     DataSet ds = db.ExecuteDataSet(dbc);

           

this.DropDownList2.DataSource = ds.Tables[0]. DefaultView;

                     this.DropDownList2. DataTextField = " RoleName ";   / /类型为字符

                    / /this. DropDownList.DataValueField = "列名";       类型为value

                   14:10:14  DropDownList2.DataBind();

posted on 2006-03-09 14:11  北回归线  阅读(360)  评论(1编辑  收藏  举报