コード例 #1
0
        private void CustomerDetailView_ItemCommand(object sender, DetailsViewCommandEventArgs e)
        {
            if (e.CommandName == "New")
            {
                // add mode
                CustomerDetailView.ChangeMode(DetailsViewMode.Insert);
                CustomerDetailView.HeaderText = "Add new customer";
            }
            else if (e.CommandName == "Edit")
            {
                // set to edit mode
                CustomerDetailView.ChangeMode(DetailsViewMode.Edit);

                // get selected customer Id
                string customerID = CustomerDetailView.HeaderText.Replace("Read only mode - Customer ID : ", "");
                // rebind data
                Customer customer = _customerRepository.GetCustomerByID(customerID);
                CustomerDetailView.HeaderText = "Edit mode - Customer ID : " + customer.CustomerID;
                CustomerDetailView.DataSource = new List <Customer> {
                    customer
                };
                CustomerDetailView.DataBind();
            }
            else if (e.CommandName == "Cancel")
            {
                // unbind any data on cancel button press
                CustomerDetailView.DataSource = null;
                CustomerDetailView.DataBind();
            }
            else if (e.CommandName == "Insert")
            {
                // insert data
            }
        }
コード例 #2
0
 // on gird view selection
 private void CustomerByCountryGrid_SelectedIndexChanged(object sender, EventArgs e)
 {
     try
     {
         string   selectedCustomerID = CustomerByCountryGrid.SelectedDataKey.Value.ToString();
         Customer customer           = _customerRepository.GetCustomerByID(selectedCustomerID);
         CustomerDetailView.ChangeMode(DetailsViewMode.ReadOnly);
         CustomerDetailView.HeaderText = "Read only mode - Customer ID : " + customer.CustomerID;                                    // Edit and delete purposes
         CustomerDetailView.DataSource = new List <Customer> {
             customer
         };
         CustomerDetailView.DataBind();
     }
     catch (Exception)
     {
         throw;
     }
 }