protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         DetailsView1.DataSource = TestDataData.GetStaff();
         DetailsView1.DataBind();
     }
 }
Esempio n. 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Hashtable
                    ht = new Hashtable(3);

                ht.Add("1st", "1");
                ht.Add("2nd", "2");
                ht.Add("3rd", "3");

                Select1.DataSource          = ht;
                Select2.DataSource          = ht;
                ListBox1.DataSource         = ht;
                DropDownList1.DataSource    = ht;
                RadioButtonList1.DataSource = ht;
                CheckBoxList1.DataSource    = ht;

                DataBind();

                OleDbConnection
                    connection = new OleDbConnection(TestDataData.GetConnectionString());

                connection.Open();

                OleDbCommand
                    cmd = connection.CreateCommand();

                cmd.CommandType = CommandType.Text;
                cmd.CommandText = "select id, name from staff order by id";

                OleDbDataReader
                    dr = cmd.ExecuteReader();

                ListBoxNames.DataSource = dr;
                ListBoxNames.DataBind();
                dr.Close();
                connection.Close();

                // DataBind(); // System.InvalidOperationException: Invalid attempt to FieldCount when reader is closed.
            }
        }