zoukankan      html  css  js  c++  java
  • asp.net dropdownlist和listbox

    if (!IsPostBack) 
            {
                //页面初次加载时执行这里的内容
                DataSet ds = new DataSet(); //数据集
                ds.Tables.Add("stu");
                ds.Tables["stu"].Columns.Add("id",typeof(int));
                ds.Tables["stu"].Columns.Add("name", typeof(string));
                ds.Tables["stu"].Columns.Add("score", 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 });
                this.ListBox1.DataSource = ds.Tables["stu"];
                this.ListBox1.DataTextField = "name"; //列表显示的字段
                this.ListBox1.DataValueField = "id";
                this.ListBox1.DataBind();
    
                //this.ListBox1.SelectedIndex  选中项的索引
                //this.ListBox1.SelectedItem   选中项
                //this.ListBox1.SelectedItem.Text   选中项的内容
                //this.ListBox1.SelectedItem.Value;  选中项的值
                //this.ListBox1.SelectedValue     选中项的值
            
                
            }
    

      

  • 相关阅读:
    HTTP状态码的详细解释,供参考
    js中实现页面跳转(返回前一页、后一页)
    CRUD工程师——基础容器LinkedList
    CRUD工程师——基础容器ArrayList
    Servlet入门
    Linux
    flex弹性布局
    div布局
    递归函数
    运算符
  • 原文地址:https://www.cnblogs.com/mengluo/p/5976094.html
Copyright © 2011-2022 走看看