3.6向listbox控件绑定数据
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace Sample5_5
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
//数据生成
DataSet ds = new DataSet();
ds.Tables.Add("stu");
ds.Tables["stu"].Columns.Add("stuNo", typeof(int));
ds.Tables["stu"].Columns.Add("stuName", typeof(string));
ds.Tables["stu"].Columns.Add("stuScore", typeof(int));
ds.Tables["stu"].Rows.Add(new object[] { 1, "鸡", 100 });
ds.Tables["stu"].Rows.Add(new object[] { 2, "鸭子", 100 });
ds.Tables["stu"].Rows.Add(new object[] { 3, "鹅", 100 });
ds.Tables["stu"].Rows.Add(new object[] { 4, "猪", 100 });
ds.Tables["stu"].Rows.Add(new object[] { 5, "狗", 100 });
//绑定数据到ListBox控件
this.BulletedList1.DataSource = ds.Tables["stu"];
this.BulletedList1.DataValueField = "stuNo";
this.BulletedList1.DataTextField = "stuName";
this.BulletedList1.DataBind();
}
}
}
}