ASP.NET(C#)中如何对ListBox进行数据绑定

来源:百度知道 编辑:UC知道 时间:2024/05/10 16:49:23
如何让ListBox显示指定数据库指定表中的数据呢?
请给下代码看看吧,谢谢

this.ListBox1.DataTextField = "NewsID";//绑定数据库中表的某列列名
this.ListBox1.DataSource = ds.Tables["News"];//数据集DataSet
this.ListBox1.DataBind();

strSql="select Classid,AClassName from ArticleClass";
DataSet ds=LinkAccess.ReturnDataSet(strSql,"ArticleClass");
if(ds.Tables["ArticleClass"].Rows.Count>0)
{
this.NewListBox.DataSource=ds.Tables["ArticleClass"].DefaultView;
this.NewListBox.DataTextField="AClassName";
this.NewListBox.DataValueField="Classid";
this.NewListBox.DataBind();
}