3.6向listbox控件绑定数据

3.6向listbox控件绑定数据

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();
            }

        }
    }
}

猜你喜欢

转载自blog.csdn.net/weixin_43299438/article/details/84023143