datalist控件显示数据 DropDownList怎样与数据库中的数据绑定?

首页 / 新闻动态 / datalist控件显示数据 DropDownList怎样与数据库中的数据绑定?

datalist控件显示数据 DropDownList怎样与数据库中的数据绑定?

DropDownList怎样与数据库中的数据绑定?

第一步:连接数据库第二步:取得数据/第三步:为其指定数据源第四步:指定其text和value值。第五步:绑定参考代码:SqlConnectioncon3=newSqlConnection("Server=.userid=sapassword=123456Database=FABS")con3.Open()SqlCommandcmd3=newSqlCommand()cmd3.CommandText="select*fromsheng"cmd3.CommandType=CommandType.Textcmd3.Connection=con3SqlDataReadersdr3=cmd3.ExecuteReader()DropDownList1.DataSource=sdr3DropDownList1.DataTextField="shengming"DropDownList1.DataBind()con3.Close()

datalist控件显示数据如何制作省份城市下拉列表dropdownlist添加列表项