protected void OnRowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            GridView1.EditIndex = -1;
            DataTable dt = DBLayer.SelectRecords();

            GridView1.DataSource = dt;
            GridView1.DataBind();
        }
        protected void OnRowEditing(object sender, GridViewEditEventArgs e)
        {
            GridView1.EditIndex = e.NewEditIndex;
            DataTable dt = DBLayer.SelectRecords();

            GridView1.DataSource = dt;
            GridView1.DataBind();
            ClearTextData();
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!this.IsPostBack)
     {
         DataTable dt = DBLayer.SelectRecords();
         GridView1.DataSource = dt;
         GridView1.DataBind();
     }
 }
        protected void OnRowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int Id = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Values[0]);

            DBLayer.Delete(Id);
            DataTable dt = DBLayer.SelectRecords();

            GridView1.DataSource = dt;
            GridView1.DataBind();
        }
        protected void Insert(object sender, EventArgs e)
        {
            ContactModel oContactModel = new ContactModel();

            oContactModel.FirstName   = txtFirstName1.Text;
            oContactModel.LastName    = txtLastName1.Text;
            oContactModel.PhoneNumber = txtPhoneNumber1.Text;
            oContactModel.Status      = txtStatus1.Text;
            DBLayer.Insert(oContactModel);
            DataTable dt = DBLayer.SelectRecords();

            GridView1.DataSource = dt;
            GridView1.DataBind();
            ClearTextData();
        }
        protected void OnRowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            ContactModel oContactModel = new ContactModel();

            GridViewRow row = GridView1.Rows[e.RowIndex];
            int         Id  = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Values[0]);

            oContactModel.FirstName   = (row.FindControl("txtFirstName") as TextBox).Text;
            oContactModel.LastName    = (row.FindControl("txtLastName") as TextBox).Text;
            oContactModel.PhoneNumber = (row.FindControl("txtPhoneNumber") as TextBox).Text;
            oContactModel.Status      = (row.FindControl("txtStatus") as TextBox).Text;
            DBLayer.Update(oContactModel, Id);
            GridView1.EditIndex = -1;
            DataTable dt = DBLayer.SelectRecords();

            GridView1.DataSource = dt;
            GridView1.DataBind();
        }