protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            if (!Page.IsValid) return;

            BLTunnit tunti = new BLTunnit();
            tunti.koodaaja = txtkoodaaja.Text;
            tunti.paivamaara = txtpvm.Text;
            tunti.tuntimaara = txttuntimaara.Text;
            tunti.minuutit = txtminuutit.Text;
            tunti.id = Convert.ToInt64(hndId.Value);

            TunnitDAL objTuntiDAL = new TunnitDAL();
            if ((hndId.Value.Trim().Length > 0) &&
                (Convert.ToInt64(hndId.Value) > 0))
                objTuntiDAL.Update(tunti);
            else
                objTuntiDAL.Create(tunti);

            ClearScreen();
            BindGrid();
            lblMessage.Text = "Record saved successfully";
        }
        catch (Exception ex)
        {
            lblMessage.Text = "There is an error occured while processing the request. Please verify the code!";
        }
    }
    protected void grdViewTunti_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        try
        {
            string strId = grdtunnit.Rows[e.RowIndex].Cells[2].Text.Trim();
            if (strId.Length > 0)
            {
                TunnitDAL objTuntiDAL = new TunnitDAL();
                objTuntiDAL.Delete(strId);

                ClearScreen();
                BindGrid();
                lblMessage.Text = "Record deleted successfully";
            }
        }
        catch (Exception ex)
        {
            lblMessage.Text = "There is an error occured while processing the request. Please verify the code!";
        }
    }
 private void BindGrid()
 {
     TunnitDAL objTuntiDAL = new TunnitDAL();
     grdtunnit.DataSource = objTuntiDAL.GetAll();
     grdtunnit.DataBind();
 }
    protected void grdViewTunti_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
    {
        hndId.Value = grdtunnit.Rows[e.NewSelectedIndex].Cells[2].Text.Trim();
        if (hndId.Value.Length > 0)
        {
            TunnitDAL objTuntiDAL = new TunnitDAL();
            BLTunnit tunti = objTuntiDAL.Get(hndId.Value);

            txtkoodaaja.Text = tunti.koodaaja;
            txtpvm.Text = tunti.paivamaara;
            txttuntimaara.Text = tunti.tuntimaara;
            txtminuutit.Text = tunti.minuutit;

            lblMessage.Text = "";
        }
    }