private void ValidateBeforeSave() { if (txtFirstName.Text == string.Empty || txtLastName.Text == string.Empty || txtPhoneNo.Text == string.Empty) { Clear(); ShowFailureMessage(); } else { PhoneDetails phoneDetails = new PhoneDetails { PhoneBookId = 0, Address = txtAddress.Text.Trim(), Email = txtEmail.Text.Trim(), FirstName = txtFirstName.Text.Trim(), LastName = txtLastName.Text.Trim(), MiddleName = txtMiddleName.Text.Trim(), PhoneNo = txtPhoneNo.Text.Trim() }; PhoneBookBL.AddPhoneBookDetails(phoneDetails); Clear(); ShowSuccessMessage(); ShowData(); } }
protected void phoneBookGrid_RowDeleting(object sender, GridViewDeleteEventArgs e) { var phoneBookId = Convert.ToInt32((phoneBookGrid.Rows[e.RowIndex].FindControl("lblID") as Label).Text); PhoneBookBL.DeletePhoneBookDetailById(phoneBookId); phoneBookGrid.EditIndex = -1; ShowData(); Clear(); }
protected void ShowData() { if (txtSearch.Text == string.Empty) { phoneBookGrid.DataSource = PhoneBookBL.GetAllPhoneBookDetails(); phoneBookGrid.DataBind(); } else { phoneBookGrid.DataSource = PhoneBookBL.GetPhoneDetailsBySearch(txtSearch.Text); phoneBookGrid.DataBind(); } }
protected void phoneBookGrid_RowUpdating(object sender, System.Web.UI.WebControls.GridViewUpdateEventArgs e) { PhoneDetails phoneDetail = new PhoneDetails(); phoneDetail.PhoneBookId = Convert.ToInt32((phoneBookGrid.Rows[e.RowIndex].FindControl("lblID") as Label).Text); phoneDetail.FirstName = (phoneBookGrid.Rows[e.RowIndex].FindControl("txtFirstName") as TextBox).Text; phoneDetail.MiddleName = (phoneBookGrid.Rows[e.RowIndex].FindControl("txtMiddleName") as TextBox).Text; phoneDetail.LastName = (phoneBookGrid.Rows[e.RowIndex].FindControl("txtLastName") as TextBox).Text; phoneDetail.Email = (phoneBookGrid.Rows[e.RowIndex].FindControl("txtEmail") as TextBox).Text; phoneDetail.PhoneNo = (phoneBookGrid.Rows[e.RowIndex].FindControl("txtPhoneNo") as TextBox).Text; phoneDetail.Address = (phoneBookGrid.Rows[e.RowIndex].FindControl("txtAddress") as TextBox).Text; PhoneBookBL.UpdatePhoneBookDetails(phoneDetail); phoneBookGrid.EditIndex = -1; Clear(); ShowSuccessMessage(); ShowData(); }