Ejemplo n.º 1
0
        protected void BindData()
        {
            DataSet   ds        = new DataSet();
            DataTable FromTable = new DataTable();

            conn.Open();
            string         query = "SELECT * FROM Customer";
            SqlCommand     cmd   = new SqlCommand(query, conn);
            SqlDataAdapter sda   = new SqlDataAdapter(cmd);

            sda.Fill(ds);
            cmd.ExecuteNonQuery();
            FromTable = ds.Tables[0];
            if (FromTable.Rows.Count > 0)
            {
                GridViewCustomerDetails.DataSource = FromTable;
                GridViewCustomerDetails.DataBind();
            }
            else
            {
                FromTable.Rows.Add(FromTable.NewRow());
                GridViewCustomerDetails.DataSource = FromTable;
                GridViewCustomerDetails.DataBind();
                int TotalColumns = GridViewCustomerDetails.Rows[0].Cells.Count;
                GridViewCustomerDetails.Rows[0].Cells.Clear();
                GridViewCustomerDetails.Rows[0].Cells.Add(new TableCell());
                GridViewCustomerDetails.Rows[0].Cells[0].ColumnSpan = TotalColumns;
                GridViewCustomerDetails.Rows[0].Cells[0].Text       = "No records Found";
            }

            ds.Dispose();
            conn.Close();
        }
Ejemplo n.º 2
0
        protected void UpdateButton_Click(object sender, EventArgs e)
        {
            try
            {
                int    Id        = int.Parse(txtCustomerId.Text);
                string FirstName = txtFirstName.Text.Trim();
                string LastName  = txtLastName.Text.Trim();
                string Email     = txtEmail.Text.Trim();
                string Address1  = txtAddress1.Text.Trim();
                string Address2  = txtAddress2.Text.Trim();
                string City      = txtCity.Text.Trim();
                string State     = txtState.Text.Trim();
                string Zip       = txtZip.Text.Trim();
                string Country   = txtCountry.Text.Trim();

                proxy = new ServiceReference1.Service1Client();
                ServiceReference1.Customer oldCustomer =
                    new ServiceReference1.Customer()
                {
                    Id        = Id,
                    FirstName = FirstName,
                    LastName  = LastName,
                    Email     = Email,
                    Address1  = Address1,
                    Address2  = Address2,
                    City      = City,
                    State     = State,
                    Zip       = Zip,
                    Country   = Country
                };

                proxy.UpdateCustomers(oldCustomer);

                GridViewCustomerDetails.DataSource = proxy.GetCustomers();
                GridViewCustomerDetails.DataBind();
                lblMsg.Text = "Record Updated Successfully";
            }
            catch (FaultException <ExceptionMessage> exceptionFromService)
            {
                lblMsg.Text = "Error while updating customer details :" + exceptionFromService.Detail.errorMessageOfAction;
            }
            catch (Exception exception)
            {
                lblMsg.Text = "Error while updating customer details :" + exception.Message;
            }

            ResetAll();
        }
Ejemplo n.º 3
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         try
         {
             proxy = new ServiceReference1.Service1Client();
             GridViewCustomerDetails.DataSource = proxy.GetCustomers();
             GridViewCustomerDetails.DataBind();
         }
         catch (FaultException <ExceptionMessage> exceptionFromService)
         {
             lblMsg.Text = "Error while loading customer details :" + exceptionFromService.Detail.errorMessageOfAction;
         }
         catch (Exception exception)
         {
             lblMsg.Text = "Error while loading customer details :" + exception.Message;
         }
     }
 }
Ejemplo n.º 4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Customer cs = new Customer();

            DdlCountry.DataSource     = cs.LoadCountries();
            DdlCountry.DataTextField  = "CountryName";
            DdlCountry.DataValueField = "ID";
            DdlCountry.DataBind();
            ListItem li = new ListItem("Choose", "0");

            DdlCountry.Items.Add(li);
            DdlCountry.SelectedValue = "0";


            DataSet DT = cs.LoadCustomer();

            GridViewCustomerDetails.DataSource = DT.Tables[0];
            GridViewCustomerDetails.DataBind();


            DisplayHobbies();
            Panel1.DataBind();
        }