protected void btnSubmit_Click(object sender, EventArgs e) { User aUser = new User(); aUser.FirstName = txtBoxFName.Text; aUser.LastName = txtBoxLName.Text; aUser.PhoneNumber = txtBoxContact.Text; aUser.Email = txtBoxEmail.Text; aUser.StreetNumber = txtBoxStreetNumber.Text; aUser.StreetAddress = txtBoxStreetAddress.Text; aUser.PostCode = txtBoxPostCode.Text; aUser.District = txtBoxDistrict.Text; aUser.Country = txtBoxCountry.Text; UserDataBaseHandler userDataBaseHandler = new UserDataBaseHandler(); if (RadioButtonListGender.SelectedItem != null) { aUser.Gender = RadioButtonListGender.SelectedValue; } else { aUser.Gender = ""; } try { if (userDataBaseHandler.InsertUserDataToDB(aUser)) { Response.Write("<script>alert('Your information has been inserted successfully!');</script>"); ClearAllFormElements(); } } catch (SqlException sqlException) { Response.Write("<script>alert('Data could not be saved' " + sqlException.Message + ");</script>"); } catch (Exception exception) { Response.Write("<script>alert('Error occured');</script>"); } }
protected void Page_Load(object sender, EventArgs e) { UserDataBaseHandler userDataBaseHandler = new UserDataBaseHandler(); List <User> userList = new List <User>(); try { userList = userDataBaseHandler.GetAllUsers(); AllUserGridView.DataSource = userList; AllUserGridView.DataBind(); } catch (SqlException sqlException) { Response.Write("<script>alert('Error occured while retriving data from Database');</script>"); } catch (Exception exceptoinObj) { Response.Write("<script>alert('Error occured');</script>"); } }